summaryrefslogtreecommitdiffstats
path: root/ui/native_theme
diff options
context:
space:
mode:
authorweiliangc@chromium.org <weiliangc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-18 20:50:47 +0000
committerweiliangc@chromium.org <weiliangc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-18 20:50:47 +0000
commite3d512a71352fe9060e168c52c3b4583a4558852 (patch)
treea298c359f67c83c5b2e3874691e98e5361a5458e /ui/native_theme
parent3e99f1afa25a9af7efb3d2a838fed79d520f1dbb (diff)
downloadchromium_src-e3d512a71352fe9060e168c52c3b4583a4558852.zip
chromium_src-e3d512a71352fe9060e168c52c3b4583a4558852.tar.gz
chromium_src-e3d512a71352fe9060e168c52c3b4583a4558852.tar.bz2
Add 9 patch scrollbar assets to native theme
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
Diffstat (limited to 'ui/native_theme')
-rw-r--r--ui/native_theme/native_theme.gyp2
-rw-r--r--ui/native_theme/native_theme_aura.cc88
-rw-r--r--ui/native_theme/native_theme_aura.h33
-rw-r--r--ui/native_theme/native_theme_switches.cc31
-rw-r--r--ui/native_theme/native_theme_switches.h25
5 files changed, 177 insertions, 2 deletions
diff --git a/ui/native_theme/native_theme.gyp b/ui/native_theme/native_theme.gyp
index dcbf0dc..a50a532 100644
--- a/ui/native_theme/native_theme.gyp
+++ b/ui/native_theme/native_theme.gyp
@@ -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',
],
diff --git a/ui/native_theme/native_theme_aura.cc b/ui/native_theme/native_theme_aura.cc
index bcec3fa..ec192d2 100644
--- a/ui/native_theme/native_theme_aura.cc
+++ b/ui/native_theme/native_theme_aura.cc
@@ -4,6 +4,8 @@
#include "ui/native_theme/native_theme_aura.h"
+#include <limits>
+
#include "base/logging.h"
#include "grit/ui_resources.h"
#include "ui/base/layout.h"
@@ -17,6 +19,7 @@
#include "ui/gfx/skbitmap_operations.h"
#include "ui/gfx/skia_util.h"
#include "ui/native_theme/common_theme.h"
+#include "ui/native_theme/native_theme_switches.h"
using gfx::NineImagePainter;
@@ -40,6 +43,26 @@ const int kScrollbarArrowButtonImages[NativeTheme::kMaxState][9] = {
IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED)
};
+const uint8 kScrollbarOverlayThumbFillAlphas[NativeTheme::kMaxState] = {
+ 0, // Does not matter, will not paint for disabled state.
+ 178, // Hover state, opacity 70%, alpha would be 0.7 * 255.
+ 140, // Normal state, opacity 55%, alpha would be 0.55 * 255.
+ 178 // Pressed state, opacity 70%, alpha would be 0.7 * 255.
+};
+
+const uint8 kScrollbarOverlayThumbStrokeAlphas[NativeTheme::kMaxState] = {
+ 0, // Does not matter, will not paint for disabled state.
+ 51, // Hover state, opacity 20%, alpha would be 0.2 * 255.
+ 38, // Normal state, opacity 15%, alpha would be 0.15 * 255.
+ 51 // Pressed state, opacity 20%, alpha would be 0.2 * 255.
+};
+
+const int kScrollbarOverlayThumbStrokeImages[9] =
+ IMAGE_GRID_NO_CENTER(IDR_SCROLLBAR_OVERLAY_THUMB_STROKE);
+
+const int kScrollbarOverlayThumbFillImages[9] =
+ IMAGE_GRID(IDR_SCROLLBAR_OVERLAY_THUMB_FILL);
+
const int kScrollbarTrackImages[9] = IMAGE_GRID(IDR_SCROLLBAR_BASE);
} // namespace
@@ -63,7 +86,7 @@ NativeThemeAura::NativeThemeAura() {
set_scrollbar_button_length(0);
#endif
- // Image declarations assume the following order.
+ // Images and alphas declarations assume the following order.
COMPILE_ASSERT(kDisabled == 0, states_unexepctedly_changed);
COMPILE_ASSERT(kHovered == 1, states_unexepctedly_changed);
COMPILE_ASSERT(kNormal == 2, states_unexepctedly_changed);
@@ -142,6 +165,8 @@ void NativeThemeAura::PaintScrollbarTrack(
State state,
const ScrollbarTrackExtraParams& extra_params,
const gfx::Rect& rect) const {
+ // Overlay Scrollbar should never paint a scrollbar track.
+ DCHECK(!IsOverlayScrollbarEnabled());
if (!scrollbar_track_painter_)
scrollbar_track_painter_ = CreateNineImagePainter(kScrollbarTrackImages);
PaintPainter(scrollbar_track_painter_.get(), sk_canvas, rect);
@@ -152,6 +177,24 @@ void NativeThemeAura::PaintScrollbarThumb(SkCanvas* sk_canvas,
State state,
const gfx::Rect& rect) const {
gfx::Rect thumb_rect(rect);
+ if (IsOverlayScrollbarEnabled()) {
+ // Overlay scrollbar has no track, just paint thumb directly.
+ // Do not paint if state is disabled.
+ if (state == kDisabled)
+ return;
+
+ if (!scrollbar_overlay_thumb_painter_) {
+ scrollbar_overlay_thumb_painter_ =
+ CreateDualPainter(kScrollbarOverlayThumbFillImages,
+ kScrollbarOverlayThumbFillAlphas,
+ kScrollbarOverlayThumbStrokeImages,
+ kScrollbarOverlayThumbStrokeAlphas);
+ }
+
+ PaintDualPainter(
+ scrollbar_overlay_thumb_painter_.get(), sk_canvas, thumb_rect, state);
+ return;
+ }
// If there are no scrollbuttons then provide some padding so that thumb
// doesn't touch the top of the track.
const int extra_padding = (scrollbar_button_length() == 0) ? 2 : 0;
@@ -161,12 +204,15 @@ void NativeThemeAura::PaintScrollbarThumb(SkCanvas* sk_canvas,
thumb_rect.Inset(extra_padding, 2, extra_padding, 2);
PaintPainter(GetOrCreatePainter(
kScrollbarThumbImages, state, scrollbar_thumb_painters_),
- sk_canvas, thumb_rect);
+ sk_canvas,
+ thumb_rect);
}
void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas,
State state,
const gfx::Rect& rect) const {
+ // Overlay Scrollbar should never paint a scrollbar corner.
+ DCHECK(!IsOverlayScrollbarEnabled());
SkPaint paint;
paint.setColor(SkColorSetRGB(0xF1, 0xF1, 0xF1));
paint.setStyle(SkPaint::kFill_Style);
@@ -197,4 +243,42 @@ void NativeThemeAura::PaintPainter(NineImagePainter* painter,
painter->Paint(canvas.get(), rect);
}
+scoped_ptr<NativeThemeAura::DualPainter> NativeThemeAura::CreateDualPainter(
+ const int fill_image_ids[9],
+ const uint8 fill_alphas[kMaxState],
+ const int stroke_image_ids[9],
+ const uint8 stroke_alphas[kMaxState]) const {
+ scoped_ptr<NativeThemeAura::DualPainter> dual_painter(
+ new NativeThemeAura::DualPainter(CreateNineImagePainter(fill_image_ids),
+ fill_alphas,
+ CreateNineImagePainter(stroke_image_ids),
+ stroke_alphas));
+ return dual_painter.Pass();
+}
+
+void NativeThemeAura::PaintDualPainter(
+ NativeThemeAura::DualPainter* dual_painter,
+ SkCanvas* sk_canvas,
+ const gfx::Rect& rect,
+ State state) const {
+ DCHECK(dual_painter);
+ scoped_ptr<gfx::Canvas> canvas(CreateCanvas(sk_canvas));
+ dual_painter->fill_painter->Paint(
+ canvas.get(), rect, dual_painter->fill_alphas[state]);
+ dual_painter->stroke_painter->Paint(
+ canvas.get(), rect, dual_painter->stroke_alphas[state]);
+}
+
+NativeThemeAura::DualPainter::DualPainter(
+ scoped_ptr<NineImagePainter> fill_painter,
+ const uint8 fill_alphas[kMaxState],
+ scoped_ptr<NineImagePainter> stroke_painter,
+ const uint8 stroke_alphas[kMaxState])
+ : fill_painter(fill_painter.Pass()),
+ fill_alphas(fill_alphas),
+ stroke_painter(stroke_painter.Pass()),
+ stroke_alphas(stroke_alphas) {}
+
+NativeThemeAura::DualPainter::~DualPainter() {}
+
} // namespace ui
diff --git a/ui/native_theme/native_theme_aura.h b/ui/native_theme/native_theme_aura.h
index 8674eeb..65c70ff 100644
--- a/ui/native_theme/native_theme_aura.h
+++ b/ui/native_theme/native_theme_aura.h
@@ -73,6 +73,39 @@ class NATIVE_THEME_EXPORT NativeThemeAura : public FallbackTheme {
mutable scoped_ptr<gfx::NineImagePainter>
scrollbar_arrow_button_painters_[kMaxState];
+ private:
+ struct DualPainter {
+ // For overlay scrollbar thumbs, fill and stroke are controlled separately,
+ // and each state is achieved by painting with different opacity. This
+ // struct bundles information of painter generated using assets and alpha
+ // value associated with each state, so that a DualPainter for overlay
+ // scrollbar thumb would only need state as input to paint correctly.
+ DualPainter(scoped_ptr<gfx::NineImagePainter> fill_painter,
+ const uint8 fill_alphas[kMaxState],
+ scoped_ptr<gfx::NineImagePainter> stroke_painter,
+ const uint8 stroke_alphas[kMaxState]);
+ ~DualPainter();
+
+ scoped_ptr<gfx::NineImagePainter> fill_painter;
+ const uint8* const fill_alphas;
+ scoped_ptr<gfx::NineImagePainter> stroke_painter;
+ const uint8* const stroke_alphas;
+ };
+
+ // Returns DualPainter from specific fill and stroke, creating if necessary.
+ scoped_ptr<DualPainter> CreateDualPainter(
+ const int fill_image_ids[9],
+ const uint8 fill_alphas[kMaxState],
+ const int stroke_image_ids[9],
+ const uint8 stroke_alphas[kMaxState]) const;
+
+ // Paints |dualPainter| into the canvas using |rect| and specific alpha.
+ void PaintDualPainter(DualPainter* dual_painter,
+ SkCanvas* sk_canvas,
+ const gfx::Rect& rect,
+ State state) const;
+
+ mutable scoped_ptr<DualPainter> scrollbar_overlay_thumb_painter_;
DISALLOW_COPY_AND_ASSIGN(NativeThemeAura);
};
diff --git a/ui/native_theme/native_theme_switches.cc b/ui/native_theme/native_theme_switches.cc
new file mode 100644
index 0000000..ba46d18
--- /dev/null
+++ b/ui/native_theme/native_theme_switches.cc
@@ -0,0 +1,31 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "ui/native_theme/native_theme_switches.h"
+
+namespace switches {
+
+// Enables overlay scrollbars on Aura or Linux. Does nothing on Mac.
+const char kEnableOverlayScrollbar[] = "enable-overlay-scrollbar";
+
+// Disables overlay scrollbars on Aura or Linux. Does nothing on Mac.
+const char kDisableOverlayScrollbar[] = "disable-overlay-scrollbar";
+
+} // namespace switches
+
+namespace ui {
+
+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;
+}
+
+} // namespace ui
diff --git a/ui/native_theme/native_theme_switches.h b/ui/native_theme/native_theme_switches.h
new file mode 100644
index 0000000..026ee70
--- /dev/null
+++ b/ui/native_theme/native_theme_switches.h
@@ -0,0 +1,25 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Defines all the command-line switches used by native theme
+
+#ifndef UI_NATIVE_THEME_NATIVE_THEME_SWITCHES_H_
+#define UI_NATIVE_THEME_NATIVE_THEME_SWITCHES_H_
+
+#include "ui/native_theme/native_theme_export.h"
+
+namespace switches {
+
+NATIVE_THEME_EXPORT extern const char kDisableOverlayScrollbar[];
+NATIVE_THEME_EXPORT extern const char kEnableOverlayScrollbar[];
+
+} // namespace switches
+
+namespace ui {
+
+NATIVE_THEME_EXPORT bool IsOverlayScrollbarEnabled();
+
+} // namespace ui
+
+#endif // UI_NATIVE_THEME_NATIVE_THEME_SWITCHES_H_