| Index: ui/native_theme/native_theme_aura_overlay.cc
|
| diff --git a/ui/native_theme/native_theme_aura_overlay.cc b/ui/native_theme/native_theme_aura_overlay.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b86ae66294b70fce10bc0224c8d50f728ba2bfaf
|
| --- /dev/null
|
| +++ b/ui/native_theme/native_theme_aura_overlay.cc
|
| @@ -0,0 +1,148 @@
|
| +// Copyright 2016 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 "ui/native_theme/native_theme_aura_overlay.h"
|
| +
|
| +#include "base/trace_event/trace_event.h"
|
| +#include "ui/gfx/skia_util.h"
|
| +#include "ui/native_theme/native_theme_switches.h"
|
| +#include "ui/native_theme/overlay_scrollbar_constants_aura.h"
|
| +
|
| +namespace ui {
|
| +
|
| +namespace {
|
| +
|
| +// Constants for painting overlay scrollbars. Other properties needed outside
|
| +// this painting code are defined in overlay_scrollbar_constants_aura.h.
|
| +constexpr int kOverlayScrollbarStrokeWidth = 1;
|
| +constexpr int kOverlayScrollbarMinimumLength = 12;
|
| +constexpr SkAlpha kOverlayScrollbarAlphaNormal = 0x4D;
|
| +constexpr SkAlpha kOverlayScrollbarAlphaHovered = 0x80;
|
| +constexpr SkAlpha kOverlayScrollbarAlphaPressed = 0x80;
|
| +
|
| +// Indexed by ScrollbarOverlayColorTheme.
|
| +constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK,
|
| + SK_ColorWHITE};
|
| +constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE,
|
| + SK_ColorBLACK};
|
| +
|
| +SkAlpha ThumbAlphaForState(NativeTheme::State state) {
|
| + switch (state) {
|
| + case NativeTheme::kDisabled:
|
| + return 0x00;
|
| + case NativeTheme::kHovered:
|
| + return kOverlayScrollbarAlphaHovered;
|
| + case NativeTheme::kNormal:
|
| + return kOverlayScrollbarAlphaNormal;
|
| + case NativeTheme::kPressed:
|
| + return kOverlayScrollbarAlphaPressed;
|
| + case NativeTheme::kNumStates:
|
| + break;
|
| + }
|
| +
|
| + NOTREACHED();
|
| + return 0xFF;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +NativeTheme* NativeTheme::GetInstanceForWeb(bool use_overlay_scrollbars) {
|
| + if (use_overlay_scrollbars)
|
| + return NativeThemeAuraOverlay::instance();
|
| +
|
| + return NativeThemeAura::instance();
|
| +}
|
| +
|
| +// static
|
| +NativeThemeAuraOverlay* NativeThemeAuraOverlay::instance() {
|
| + CR_DEFINE_STATIC_LOCAL(NativeThemeAuraOverlay, s_native_theme, ());
|
| + return &s_native_theme;
|
| +}
|
| +
|
| +NativeThemeAuraOverlay::NativeThemeAuraOverlay() {
|
| + scrollbar_width_ =
|
| + kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2;
|
| +}
|
| +
|
| +NativeThemeAuraOverlay::~NativeThemeAuraOverlay() {}
|
| +
|
| +void NativeThemeAuraOverlay::PaintScrollbarTrack(
|
| + SkCanvas* canvas,
|
| + Part part,
|
| + State state,
|
| + const ScrollbarTrackExtraParams& extra_params,
|
| + const gfx::Rect& rect) const {
|
| + NOTREACHED();
|
| +}
|
| +
|
| +void NativeThemeAuraOverlay::PaintScrollbarThumb(
|
| + SkCanvas* canvas,
|
| + Part part,
|
| + State state,
|
| + const gfx::Rect& rect,
|
| + ScrollbarOverlayColorTheme theme) const {
|
| + // Do not paint if state is disabled.
|
| + if (state == kDisabled)
|
| + return;
|
| +
|
| + TRACE_EVENT0("blink", "NativeThemeAuraOverlay::PaintScrollbarThumb");
|
| +
|
| + gfx::Rect thumb_rect(rect);
|
| + SkAlpha thumb_alpha = ThumbAlphaForState(state);
|
| +
|
| + // In overlay mode, draw a stroke (border).
|
| + {
|
| + constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth;
|
| + SkPaint paint;
|
| + paint.setColor(
|
| + SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha));
|
| + paint.setStyle(SkPaint::kStroke_Style);
|
| + paint.setStrokeWidth(kStrokeWidth);
|
| + gfx::RectF stroke_rect(thumb_rect);
|
| + constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f;
|
| + stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth);
|
| + canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint);
|
| +
|
| + // Inset the all the edges edges so we fill-in the stroke below.
|
| + thumb_rect.Inset(kStrokeWidth, kStrokeWidth);
|
| + }
|
| +
|
| + SkPaint paint;
|
| + paint.setColor(SkColorSetA(kOverlayScrollbarThumbColor[theme], thumb_alpha));
|
| + canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint);
|
| +}
|
| +
|
| +void NativeThemeAuraOverlay::PaintScrollbarCorner(SkCanvas* canvas,
|
| + State state,
|
| + const gfx::Rect& rect) const {
|
| + NOTREACHED();
|
| +}
|
| +
|
| +gfx::Size NativeThemeAuraOverlay::GetPartSize(Part part,
|
| + State state,
|
| + const ExtraParams& extra) const {
|
| + constexpr int minimum_length =
|
| + kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth;
|
| +
|
| + // Aura overlay scrollbars need a slight tweak from the base sizes.
|
| + switch (part) {
|
| + case kScrollbarHorizontalThumb:
|
| + return gfx::Size(minimum_length, scrollbar_width_);
|
| + case kScrollbarVerticalThumb:
|
| + return gfx::Size(scrollbar_width_, minimum_length);
|
| + default:
|
| + // TODO(bokan): We should probably make sure code using overlay
|
| + // scrollbars isn't asking for part sizes that don't exist. This
|
| + // currently breaks in Views layout code which indicates they aren't
|
| + // overlay aware yet. The Views code should be fixed and either this
|
| + // branch return 0 for parts that don't exist or assert NOTREACHED.
|
| + // crbug.com/657159.
|
| + break;
|
| + }
|
| +
|
| + return NativeThemeAura::GetPartSize(part, state, extra);
|
| +}
|
| +
|
| +} // namespace ui
|
|
|