| Index: cc/layers/overlay_scrollbar_layer_impl.cc
|
| diff --git a/cc/layers/overlay_scrollbar_layer_impl.cc b/cc/layers/overlay_scrollbar_layer_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..55ea7067a1f975e33bda4e78d53b7c533dc57e48
|
| --- /dev/null
|
| +++ b/cc/layers/overlay_scrollbar_layer_impl.cc
|
| @@ -0,0 +1,204 @@
|
| +// 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 "cc/layers/overlay_scrollbar_layer_impl.h"
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "base/memory/ptr_util.h"
|
| +#include "cc/input/scrollbar_animation_controller.h"
|
| +#include "cc/layers/layer.h"
|
| +#include "cc/quads/solid_color_draw_quad.h"
|
| +#include "cc/quads/texture_draw_quad.h"
|
| +#include "cc/trees/layer_tree_impl.h"
|
| +#include "cc/trees/layer_tree_settings.h"
|
| +#include "cc/trees/occlusion.h"
|
| +#include "ui/gfx/geometry/rect_conversions.h"
|
| +
|
| +namespace cc {
|
| +
|
| +std::unique_ptr<OverlayScrollbarLayerImpl> OverlayScrollbarLayerImpl::Create(
|
| + LayerTreeImpl* tree_impl,
|
| + int id,
|
| + ScrollbarOrientation orientation,
|
| + bool is_left_side_vertical_scrollbar) {
|
| + return base::WrapUnique(new OverlayScrollbarLayerImpl(
|
| + tree_impl, id, orientation, is_left_side_vertical_scrollbar));
|
| +}
|
| +
|
| +OverlayScrollbarLayerImpl::OverlayScrollbarLayerImpl(
|
| + LayerTreeImpl* tree_impl,
|
| + int id,
|
| + ScrollbarOrientation orientation,
|
| + bool is_left_side_vertical_scrollbar)
|
| + : ScrollbarLayerImplBase(tree_impl,
|
| + id,
|
| + orientation,
|
| + is_left_side_vertical_scrollbar,
|
| + true),
|
| + thumb_ui_resource_id_(0),
|
| + thumb_thickness_(0),
|
| + thumb_length_(0),
|
| + track_start_(0),
|
| + track_length_(0) {}
|
| +
|
| +OverlayScrollbarLayerImpl::~OverlayScrollbarLayerImpl() {}
|
| +
|
| +std::unique_ptr<LayerImpl> OverlayScrollbarLayerImpl::CreateLayerImpl(
|
| + LayerTreeImpl* tree_impl) {
|
| + return OverlayScrollbarLayerImpl::Create(tree_impl, id(), orientation(),
|
| + is_left_side_vertical_scrollbar());
|
| +}
|
| +
|
| +void OverlayScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
|
| + ScrollbarLayerImplBase::PushPropertiesTo(layer);
|
| +
|
| + OverlayScrollbarLayerImpl* scrollbar_layer =
|
| + static_cast<OverlayScrollbarLayerImpl*>(layer);
|
| +
|
| + scrollbar_layer->SetThumbThickness(thumb_thickness_);
|
| + scrollbar_layer->SetThumbLength(thumb_length_);
|
| + scrollbar_layer->SetTrackStart(track_start_);
|
| + scrollbar_layer->SetTrackLength(track_length_);
|
| +
|
| + scrollbar_layer->SetImageBounds(image_bounds_);
|
| + scrollbar_layer->SetAperture(aperture_);
|
| +
|
| + scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_);
|
| +}
|
| +
|
| +bool OverlayScrollbarLayerImpl::WillDraw(DrawMode draw_mode,
|
| + ResourceProvider* resource_provider) {
|
| + DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE);
|
| + return LayerImpl::WillDraw(draw_mode, resource_provider);
|
| +}
|
| +
|
| +void OverlayScrollbarLayerImpl::AppendQuads(
|
| + RenderPass* render_pass,
|
| + AppendQuadsData* append_quads_data) {
|
| + // For overlay scrollbars, the border should match the inset of the aperture
|
| + // and be symmetrical.
|
| + gfx::Rect border(aperture_.x(), aperture_.y(), aperture_.x() * 2,
|
| + aperture_.y() * 2);
|
| + gfx::Rect thumb_quad_rect(ComputeThumbQuadRect());
|
| + gfx::Rect layer_occlusion;
|
| + bool fill_center = true;
|
| + bool nearest_neighbor = false;
|
| +
|
| + quad_generator_.SetLayout(image_bounds_, thumb_quad_rect.size(), aperture_,
|
| + border, layer_occlusion, fill_center);
|
| +
|
| + SharedQuadState* shared_quad_state =
|
| + render_pass->CreateAndAppendSharedQuadState();
|
| + PopulateSharedQuadState(shared_quad_state);
|
| +
|
| + AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
|
| + append_quads_data);
|
| +
|
| + if (!thumb_ui_resource_id_)
|
| + return;
|
| +
|
| + ResourceId resource =
|
| + layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_);
|
| +
|
| + if (!resource)
|
| + return;
|
| +
|
| + std::vector<NinePatchGenerator::Patch> patches =
|
| + quad_generator_.GeneratePatches();
|
| +
|
| + const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
| + const bool opaque =
|
| + layer_tree_impl()->IsUIResourceOpaque(thumb_ui_resource_id_);
|
| + static const bool flipped = false;
|
| + static const bool premultiplied_alpha = true;
|
| +
|
| + gfx::Vector2dF offset = thumb_quad_rect.OffsetFromOrigin();
|
| +
|
| + for (const auto& patch : patches) {
|
| + gfx::Rect output_rect = gfx::ToEnclosingRect(patch.output_rect + offset);
|
| + gfx::Rect visible_rect =
|
| + draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
|
| + output_rect);
|
| + gfx::Rect opaque_rect = opaque ? visible_rect : gfx::Rect();
|
| + if (!visible_rect.IsEmpty()) {
|
| + gfx::RectF image_rect = patch.normalized_image_rect;
|
| + TextureDrawQuad* quad =
|
| + render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
|
| + quad->SetNew(shared_quad_state, output_rect, opaque_rect, visible_rect,
|
| + resource, premultiplied_alpha, image_rect.origin(),
|
| + image_rect.bottom_right(), SK_ColorTRANSPARENT,
|
| + vertex_opacity, flipped, nearest_neighbor, false);
|
| + ValidateQuadResources(quad);
|
| + }
|
| + }
|
| +}
|
| +
|
| +void OverlayScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) {
|
| + if (thumb_thickness_ == thumb_thickness)
|
| + return;
|
| + thumb_thickness_ = thumb_thickness;
|
| + NoteLayerPropertyChanged();
|
| +}
|
| +
|
| +int OverlayScrollbarLayerImpl::ThumbThickness() const {
|
| + return thumb_thickness_;
|
| +}
|
| +
|
| +void OverlayScrollbarLayerImpl::SetThumbLength(int thumb_length) {
|
| + if (thumb_length_ == thumb_length)
|
| + return;
|
| + thumb_length_ = thumb_length;
|
| + NoteLayerPropertyChanged();
|
| +}
|
| +
|
| +int OverlayScrollbarLayerImpl::ThumbLength() const {
|
| + return thumb_length_;
|
| +}
|
| +
|
| +void OverlayScrollbarLayerImpl::SetTrackStart(int track_start) {
|
| + if (track_start_ == track_start)
|
| + return;
|
| + track_start_ = track_start;
|
| + NoteLayerPropertyChanged();
|
| +}
|
| +
|
| +int OverlayScrollbarLayerImpl::TrackStart() const {
|
| + return track_start_;
|
| +}
|
| +
|
| +void OverlayScrollbarLayerImpl::SetTrackLength(int track_length) {
|
| + if (track_length_ == track_length)
|
| + return;
|
| + track_length_ = track_length;
|
| + NoteLayerPropertyChanged();
|
| +}
|
| +
|
| +void OverlayScrollbarLayerImpl::SetImageBounds(const gfx::Size& bounds) {
|
| + if (image_bounds_ == bounds)
|
| + return;
|
| + image_bounds_ = bounds;
|
| + NoteLayerPropertyChanged();
|
| +}
|
| +
|
| +void OverlayScrollbarLayerImpl::SetAperture(const gfx::Rect& aperture) {
|
| + if (aperture_ == aperture)
|
| + return;
|
| + aperture_ = aperture;
|
| + NoteLayerPropertyChanged();
|
| +}
|
| +
|
| +float OverlayScrollbarLayerImpl::TrackLength() const {
|
| + return track_length_ + (orientation() == VERTICAL ? vertical_adjust() : 0);
|
| +}
|
| +
|
| +bool OverlayScrollbarLayerImpl::IsThumbResizable() const {
|
| + return false;
|
| +}
|
| +
|
| +const char* OverlayScrollbarLayerImpl::LayerTypeAsString() const {
|
| + return "cc::OverlayScrollbarLayerImpl";
|
| +}
|
| +
|
| +} // namespace cc
|
|
|