Skip to content

Commit

Permalink
Add 9 patch scrollbar assets to native theme
Browse files Browse the repository at this point in the history
9-patch scrollbar is a prettified version of overlay scrollbar that is
going to be used on aura. Add these assets with their ID to native theme
 aura. Add logic to use 9 patch scroll bar assets when overlay scrollbar
 is enabled. Also overlay scrollbar should only be painting thumbs, thus
 when overlay scrollbar is turned on native theme shouldn't need to
paint track and scrollbar corner.

This set of assets for 9 patch scrollbar intent to control stroke and
fill separately, while stroke does not provide asset for center of
9 patch. Different state is achieved by adjusting alpha of stroke and
fill separately.

BUG=307578

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=256930

Review URL: https://codereview.chromium.org/183973008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257744 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
weiliangc@chromium.org committed Mar 18, 2014
1 parent 3e99f1a commit e3d512a
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 53 deletions.
1 change: 1 addition & 0 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "ui/gl/gl_switches.h"
#include "ui/keyboard/keyboard_switches.h"
#include "ui/message_center/message_center_switches.h"
#include "ui/native_theme/native_theme_switches.h"
#include "ui/views/views_switches.h"

#if defined(USE_ASH)
Expand Down
1 change: 1 addition & 0 deletions content/browser/android/content_startup_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "content/public/common/content_switches.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "ui/base/ui_base_switches.h"
#include "ui/native_theme/native_theme_switches.h"

namespace content {

Expand Down
1 change: 1 addition & 0 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
#include "ui/events/event_switches.h"
#include "ui/gfx/switches.h"
#include "ui/gl/gl_switches.h"
#include "ui/native_theme/native_theme_switches.h"
#include "webkit/browser/fileapi/sandbox_file_system_backend.h"
#include "webkit/common/resource_type.h"

Expand Down
3 changes: 2 additions & 1 deletion content/browser/renderer_host/render_view_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/native_theme/native_theme_switches.h"
#include "ui/shell_dialogs/selected_file_info.h"
#include "webkit/browser/fileapi/isolated_context.h"

Expand Down Expand Up @@ -447,7 +448,7 @@ WebPreferences RenderViewHostImpl::GetWebkitPrefs(const GURL& url) {
prefs.pinch_virtual_viewport_enabled = true;
prefs.pinch_overlay_scrollbar_thickness = 10;
}
prefs.use_solid_color_scrollbars = IsOverlayScrollbarEnabled();
prefs.use_solid_color_scrollbars = ui::IsOverlayScrollbarEnabled();

#if defined(OS_ANDROID)
prefs.user_gesture_required_for_media_playback = !command_line.HasSwitch(
Expand Down
3 changes: 2 additions & 1 deletion content/child/runtime_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "content/common/content_switches_internal.h"
#include "content/public/common/content_switches.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "ui/native_theme/native_theme_switches.h"

#if defined(OS_ANDROID)
#include <cpu-features.h>
Expand Down Expand Up @@ -153,7 +154,7 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
if (command_line.HasSwitch(switches::kEnableOverlayFullscreenVideo))
WebRuntimeFeatures::enableOverlayFullscreenVideo(true);

if (IsOverlayScrollbarEnabled())
if (ui::IsOverlayScrollbarEnabled())
WebRuntimeFeatures::enableOverlayScrollbars(true);

if (command_line.HasSwitch(switches::kEnableFastTextAutosizing))
Expand Down
11 changes: 0 additions & 11 deletions content/common/content_switches_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@

namespace content {

bool IsOverlayScrollbarEnabled() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();

if (command_line.HasSwitch(switches::kDisableOverlayScrollbar))
return false;
else if (command_line.HasSwitch(switches::kEnableOverlayScrollbar))
return true;

return false;
}

bool IsPinchToZoomEnabled() {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();

Expand Down
2 changes: 0 additions & 2 deletions content/common/content_switches_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace content {

// Should we use overlay scrollbars.
bool IsOverlayScrollbarEnabled();
bool IsPinchToZoomEnabled();

} // namespace content
Expand Down
6 changes: 0 additions & 6 deletions content/public/common/content_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ const char kDisableLogging[] = "disable-logging";
// Overrides the kEnableMapImage flag.
const char kDisableMapImage[] = "disable-map-image";

// Disables overlay scrollbars on Aura or Linux. Does nothing on Mac.
const char kDisableOverlayScrollbar[] = "disable-overlay-scrollbar";

// Disable Pepper3D.
const char kDisablePepper3d[] = "disable-pepper-3d";

Expand Down Expand Up @@ -495,9 +492,6 @@ const char kEnableOverlayFullscreenVideo[] = "enable-overlay-fullscreen-video";
const char kDisableOverlayFullscreenVideoSubtitle[] =
"disable-overlay-fullscreen-video-subtitle";

// Enables overlay scrollbars on Aura or Linux. Does nothing on Mac.
const char kEnableOverlayScrollbar[] = "enable-overlay-scrollbar";

// Forward overscroll event data from the renderer to the browser.
const char kEnableOverscrollNotifications[] = "enable-overscroll-notifications";

Expand Down
2 changes: 0 additions & 2 deletions content/public/common/content_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ CONTENT_EXPORT extern const char kDisableJava[];
CONTENT_EXPORT extern const char kDisableJavaScript[];
CONTENT_EXPORT extern const char kDisableLCDText[];
CONTENT_EXPORT extern const char kDisableMapImage[];
CONTENT_EXPORT extern const char kDisableOverlayScrollbar[];
CONTENT_EXPORT extern const char kDisablePrefixedEncryptedMedia[];
extern const char kDisableKillAfterBadIPC[];
CONTENT_EXPORT extern const char kDisableLocalStorage[];
Expand Down Expand Up @@ -149,7 +148,6 @@ extern const char kEnableMonitorProfile[];
CONTENT_EXPORT extern const char kEnableOfflineCacheAccess[];
CONTENT_EXPORT extern const char kEnableOverlayFullscreenVideo[];
CONTENT_EXPORT extern const char kDisableOverlayFullscreenVideoSubtitle[];
CONTENT_EXPORT extern const char kEnableOverlayScrollbar[];
CONTENT_EXPORT extern const char kEnableOverscrollNotifications[];
CONTENT_EXPORT extern const char kEnablePinch[];
extern const char kEnablePreparsedJsCaching[];
Expand Down
3 changes: 2 additions & 1 deletion content/renderer/gpu/render_widget_compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "third_party/WebKit/public/platform/WebSize.h"
#include "third_party/WebKit/public/web/WebWidget.h"
#include "ui/gl/gl_switches.h"
#include "ui/native_theme/native_theme_switches.h"
#include "webkit/renderer/compositor_bindings/web_layer_impl.h"

namespace base {
Expand Down Expand Up @@ -278,7 +279,7 @@ scoped_ptr<RenderWidgetCompositor> RenderWidgetCompositor::Create(
}

#elif !defined(OS_MACOSX)
if (IsOverlayScrollbarEnabled()) {
if (ui::IsOverlayScrollbarEnabled()) {
settings.scrollbar_animator = cc::LayerTreeSettings::Thinning;
settings.solid_color_scrollbar_color = SkColorSetARGB(128, 128, 128, 128);
} else if (cmd->HasSwitch(cc::switches::kEnablePinchVirtualViewport)) {
Expand Down
11 changes: 11 additions & 0 deletions ui/base/nine_image_painter_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
x ## _LEFT, x ## _CENTER, x ## _RIGHT, \
x ## _BOTTOM_LEFT, x ## _BOTTOM, x ## _BOTTOM_RIGHT, }

// Defines a empty image for used in macro for creating image grid for a ring of
// eight images.
#define EMPTY_IMAGE 0

// A macro to define arrays of IDR constants used with CreateImageGridPainter
// where only a ring of eight images is provided and center image is empty.
#define IMAGE_GRID_NO_CENTER(x) { x ## _TOP_LEFT, x ## _TOP, x ## _TOP_RIGHT, \
x ## _LEFT, EMPTY_IMAGE, x ## _RIGHT, \
x ## _BOTTOM_LEFT, x ## _BOTTOM, x ## _BOTTOM_RIGHT, }


namespace gfx {
class NineImagePainter;
}
Expand Down
56 changes: 37 additions & 19 deletions ui/gfx/nine_image_painter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "ui/gfx/nine_image_painter.h"

#include <limits>

#include "third_party/skia/include/core/SkPaint.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/insets.h"
Expand All @@ -12,6 +15,21 @@

namespace gfx {

namespace {

// Stretches the given image over the specified canvas area.
void Fill(Canvas* c,
const ImageSkia& i,
int x,
int y,
int w,
int h,
const SkPaint& paint) {
c->DrawImageInt(i, 0, 0, i.width(), i.height(), x, y, w, h, false, paint);
}

} // namespace

NineImagePainter::NineImagePainter(const std::vector<ImageSkia>& images) {
DCHECK_EQ(arraysize(images_), images.size());
for (size_t i = 0; i < arraysize(images_); ++i)
Expand Down Expand Up @@ -51,12 +69,22 @@ Size NineImagePainter::GetMinimumSize() const {
}

void NineImagePainter::Paint(Canvas* canvas, const Rect& bounds) {
// When no alpha value is specified, use default value of 100% opacity.
Paint(canvas, bounds, std::numeric_limits<uint8>::max());
}

void NineImagePainter::Paint(Canvas* canvas,
const Rect& bounds,
const uint8 alpha) {
if (IsEmpty())
return;

ScopedCanvas scoped_canvas(canvas);
canvas->Translate(bounds.OffsetFromOrigin());

SkPaint paint;
paint.setAlpha(alpha);

// In case the corners and edges don't all have the same width/height, we draw
// the center first, and extend it out in all directions to the edges of the
// images with the smallest widths/heights. This way there will be no
Expand All @@ -80,25 +108,15 @@ void NineImagePainter::Paint(Canvas* canvas, const Rect& bounds) {
int i4y = std::min(std::min(i0h, i1h), i2h);
int i4h = h - i4y - std::min(std::min(i6h, i7h), i8h);
if (!images_[4].isNull())
Fill(canvas, images_[4], i4x, i4y, i4w, i4h);
canvas->DrawImageInt(images_[0], 0, 0);
Fill(canvas, images_[1], i0w, 0, w - i0w - i2w, i1h);
canvas->DrawImageInt(images_[2], w - i2w, 0);
Fill(canvas, images_[3], 0, i0h, i3w, h - i0h - i6h);
Fill(canvas, images_[5], w - i5w, i2h, i5w, h - i2h - i8h);
canvas->DrawImageInt(images_[6], 0, h - i6h);
Fill(canvas, images_[7], i6w, h - i7h, w - i6w - i8w, i7h);
canvas->DrawImageInt(images_[8], w - i8w, h - i8h);
}

// static
void NineImagePainter::Fill(Canvas* c,
const ImageSkia& i,
int x,
int y,
int w,
int h) {
c->DrawImageInt(i, 0, 0, i.width(), i.height(), x, y, w, h, false);
Fill(canvas, images_[4], i4x, i4y, i4w, i4h, paint);
canvas->DrawImageInt(images_[0], 0, 0, paint);
Fill(canvas, images_[1], i0w, 0, w - i0w - i2w, i1h, paint);
canvas->DrawImageInt(images_[2], w - i2w, 0, paint);
Fill(canvas, images_[3], 0, i0h, i3w, h - i0h - i6h, paint);
Fill(canvas, images_[5], w - i5w, i2h, i5w, h - i2h - i8h, paint);
canvas->DrawImageInt(images_[6], 0, h - i6h, paint);
Fill(canvas, images_[7], i6w, h - i7h, w - i6w - i8w, i7h, paint);
canvas->DrawImageInt(images_[8], w - i8w, h - i8h, paint);
}

} // namespace gfx
9 changes: 1 addition & 8 deletions ui/gfx/nine_image_painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@ class GFX_EXPORT NineImagePainter {
bool IsEmpty() const;
Size GetMinimumSize() const;
void Paint(Canvas* canvas, const Rect& bounds);
void Paint(Canvas* canvas, const Rect& bounds, uint8 alpha);

private:
// Stretches the given image over the specified canvas area.
static void Fill(Canvas* c,
const ImageSkia& i,
int x,
int y,
int w,
int h);

// Images are numbered as depicted below.
// ____________________
// |__i0__|__i1__|__i2__|
Expand Down
2 changes: 2 additions & 0 deletions ui/native_theme/native_theme.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
'native_theme_gtk.h',
'native_theme_mac.h',
'native_theme_mac.mm',
'native_theme_switches.cc',
'native_theme_switches.h',
'native_theme_win.cc',
'native_theme_win.h',
],
Expand Down
Loading

0 comments on commit e3d512a

Please sign in to comment.