Skip to content

Commit

Permalink
Use nine-patch resource for drawing Aura overlay scrollbar thumb.
Browse files Browse the repository at this point in the history
This patch factors out the nine-patch generation from NinePatchLayer
into a NinePatchGenerator and uses it to create a nine-patch scrollbar
layer that can change size without a repaint. This is used only in the
compositor. Scrollbars painted in Blink paint to the full required size.

The new scrollbar type is implemented in OverlayScrollbarLayer and Impl.
We add methods to NativeTheme to draw 9-patch versions of a theme part,
currently implemented for the scrollbar thumb for overlays in
NativeThemeAura. The NativeTheme provides two methods:

NinePatchCanvasSize() returns the size of the smallest canvas onto which
a nine patch part can be drawn.

NinePatchAperture() returns the rect in the canvas, whose size is
provided by the method above, which will be used as the middle patch in
the resource. Resizing the part will stretch only the middle patch in
both directions.

This is used mainly for the thinning animation in Aura overlay
scrollbars. We still need to repaint due to hover and pressed effects.
Technically, we could avoid repainting on size changes too but this would
require some additional work.

BUG=669670
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2591863003
Cr-Commit-Position: refs/heads/master@{#454413}
  • Loading branch information
bokand authored and Commit bot committed Mar 2, 2017
1 parent 924779f commit e7a058a
Show file tree
Hide file tree
Showing 45 changed files with 1,692 additions and 396 deletions.
7 changes: 7 additions & 0 deletions cc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ cc_component("cc") {
"layers/nine_patch_layer_impl.cc",
"layers/nine_patch_layer_impl.h",
"layers/paint_properties.h",
"layers/painted_overlay_scrollbar_layer.cc",
"layers/painted_overlay_scrollbar_layer.h",
"layers/painted_overlay_scrollbar_layer_impl.cc",
"layers/painted_overlay_scrollbar_layer_impl.h",
"layers/painted_scrollbar_layer.cc",
"layers/painted_scrollbar_layer.h",
"layers/painted_scrollbar_layer_impl.cc",
Expand Down Expand Up @@ -282,6 +286,8 @@ cc_component("cc") {
"quads/draw_quad.h",
"quads/largest_draw_quad.cc",
"quads/largest_draw_quad.h",
"quads/nine_patch_generator.cc",
"quads/nine_patch_generator.h",
"quads/picture_draw_quad.cc",
"quads/picture_draw_quad.h",
"quads/render_pass.cc",
Expand Down Expand Up @@ -807,6 +813,7 @@ cc_test("cc_unittests") {
"playback/recording_source_unittest.cc",
"quads/draw_polygon_unittest.cc",
"quads/draw_quad_unittest.cc",
"quads/nine_patch_generator_unittest.cc",
"quads/render_pass_unittest.cc",
"raster/raster_buffer_provider_unittest.cc",
"raster/scoped_gpu_raster_unittest.cc",
Expand Down
12 changes: 12 additions & 0 deletions cc/blink/scrollbar_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ bool ScrollbarImpl::NeedsPaintPart(cc::ScrollbarPart part) const {
return painter_.trackNeedsRepaint();
}

bool ScrollbarImpl::UsesNinePatchThumbResource() const {
return painter_.usesNinePatchThumbResource();
}

gfx::Size ScrollbarImpl::NinePatchThumbCanvasSize() const {
return geometry_->ninePatchThumbCanvasSize(scrollbar_.get());
}

gfx::Rect ScrollbarImpl::NinePatchThumbAperture() const {
return geometry_->ninePatchThumbAperture(scrollbar_.get());
}

void ScrollbarImpl::PaintPart(cc::PaintCanvas* canvas,
cc::ScrollbarPart part,
const gfx::Rect& content_rect) {
Expand Down
4 changes: 4 additions & 0 deletions cc/blink/scrollbar_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class ScrollbarImpl : public cc::Scrollbar {
cc::ScrollbarPart part,
const gfx::Rect& content_rect) override;

bool UsesNinePatchThumbResource() const override;
gfx::Size NinePatchThumbCanvasSize() const override;
gfx::Rect NinePatchThumbAperture() const override;

private:
std::unique_ptr<blink::WebScrollbar> scrollbar_;
blink::WebScrollbarThemePainter painter_;
Expand Down
9 changes: 9 additions & 0 deletions cc/blink/web_compositor_support_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ WebCompositorSupportImpl::createScrollbarLayer(
std::move(geometry));
}

std::unique_ptr<WebScrollbarLayer>
WebCompositorSupportImpl::createOverlayScrollbarLayer(
std::unique_ptr<WebScrollbar> scrollbar,
WebScrollbarThemePainter painter,
std::unique_ptr<WebScrollbarThemeGeometry> geometry) {
return base::MakeUnique<WebScrollbarLayerImpl>(std::move(scrollbar), painter,
std::move(geometry), true);
}

std::unique_ptr<WebScrollbarLayer>
WebCompositorSupportImpl::createSolidColorScrollbarLayer(
WebScrollbar::Orientation orientation,
Expand Down
4 changes: 4 additions & 0 deletions cc/blink/web_compositor_support_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class CC_BLINK_EXPORT WebCompositorSupportImpl
std::unique_ptr<blink::WebScrollbar> scrollbar,
blink::WebScrollbarThemePainter painter,
std::unique_ptr<blink::WebScrollbarThemeGeometry>) override;
std::unique_ptr<blink::WebScrollbarLayer> createOverlayScrollbarLayer(
std::unique_ptr<blink::WebScrollbar> scrollbar,
blink::WebScrollbarThemePainter painter,
std::unique_ptr<blink::WebScrollbarThemeGeometry>) override;
std::unique_ptr<blink::WebScrollbarLayer> createSolidColorScrollbarLayer(
blink::WebScrollbar::Orientation orientation,
int thumb_thickness,
Expand Down
13 changes: 13 additions & 0 deletions cc/blink/web_scrollbar_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include "cc/blink/scrollbar_impl.h"
#include "cc/blink/web_layer_impl.h"
#include "cc/layers/layer.h"
#include "cc/layers/painted_overlay_scrollbar_layer.h"
#include "cc/layers/painted_scrollbar_layer.h"
#include "cc/layers/scrollbar_layer_interface.h"
#include "cc/layers/solid_color_scrollbar_layer.h"

using cc::PaintedOverlayScrollbarLayer;
using cc::PaintedScrollbarLayer;
using cc::SolidColorScrollbarLayer;

Expand All @@ -39,6 +41,17 @@ WebScrollbarLayerImpl::WebScrollbarLayerImpl(
std::move(geometry)),
0))) {}

WebScrollbarLayerImpl::WebScrollbarLayerImpl(
std::unique_ptr<blink::WebScrollbar> scrollbar,
blink::WebScrollbarThemePainter painter,
std::unique_ptr<blink::WebScrollbarThemeGeometry> geometry,
bool)
: layer_(new WebLayerImpl(PaintedOverlayScrollbarLayer::Create(
base::MakeUnique<ScrollbarImpl>(std::move(scrollbar),
painter,
std::move(geometry)),
0))) {}

WebScrollbarLayerImpl::WebScrollbarLayerImpl(
blink::WebScrollbar::Orientation orientation,
int thumb_thickness,
Expand Down
5 changes: 5 additions & 0 deletions cc/blink/web_scrollbar_layer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class WebScrollbarLayerImpl : public blink::WebScrollbarLayer {
std::unique_ptr<blink::WebScrollbar> scrollbar,
blink::WebScrollbarThemePainter painter,
std::unique_ptr<blink::WebScrollbarThemeGeometry> geometry);
CC_BLINK_EXPORT WebScrollbarLayerImpl(
std::unique_ptr<blink::WebScrollbar> scrollbar,
blink::WebScrollbarThemePainter painter,
std::unique_ptr<blink::WebScrollbarThemeGeometry> geometry,
bool temp);
CC_BLINK_EXPORT WebScrollbarLayerImpl(
blink::WebScrollbar::Orientation orientation,
int thumb_thickness,
Expand Down
3 changes: 3 additions & 0 deletions cc/input/scrollbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Scrollbar {
virtual void PaintPart(PaintCanvas* canvas,
ScrollbarPart part,
const gfx::Rect& content_rect) = 0;
virtual bool UsesNinePatchThumbResource() const = 0;
virtual gfx::Size NinePatchThumbCanvasSize() const = 0;
virtual gfx::Rect NinePatchThumbAperture() const = 0;
};

} // namespace cc
Expand Down
Loading

0 comments on commit e7a058a

Please sign in to comment.