blob: ea48086fbcf4ca33d4a1b2bcbe10ecb00ac050dd [file] [log] [blame]
[email protected]3a83478b2013-08-22 20:55:171// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]94f206c12012-08-25 00:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]3a83478b2013-08-22 20:55:175#include "cc/layers/painted_scrollbar_layer_impl.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]3a73d222013-07-26 13:53:187#include <algorithm>
8
[email protected]95e4e1a02013-03-18 07:09:099#include "cc/animation/scrollbar_animation_controller.h"
[email protected]cc3cfaa2013-03-18 09:05:5210#include "cc/layers/layer.h"
[email protected]89e82672013-03-18 07:50:5611#include "cc/quads/solid_color_draw_quad.h"
12#include "cc/quads/texture_draw_quad.h"
[email protected]556fd292013-03-18 08:03:0413#include "cc/trees/layer_tree_impl.h"
14#include "cc/trees/layer_tree_settings.h"
vmpstr11b77b432014-10-07 20:11:4015#include "cc/trees/occlusion.h"
heejin.r.chungd28506ba2014-10-23 16:36:2016#include "ui/gfx/geometry/rect_conversions.h"
[email protected]94f206c12012-08-25 00:09:1417
[email protected]9c88e562012-09-14 22:21:3018namespace cc {
[email protected]94f206c12012-08-25 00:09:1419
[email protected]3a83478b2013-08-22 20:55:1720scoped_ptr<PaintedScrollbarLayerImpl> PaintedScrollbarLayerImpl::Create(
[email protected]3138b262013-03-08 18:39:0821 LayerTreeImpl* tree_impl,
22 int id,
[email protected]c28df4c12013-05-22 17:36:4923 ScrollbarOrientation orientation) {
[email protected]3a83478b2013-08-22 20:55:1724 return make_scoped_ptr(
25 new PaintedScrollbarLayerImpl(tree_impl, id, orientation));
[email protected]94f206c12012-08-25 00:09:1426}
27
[email protected]3a83478b2013-08-22 20:55:1728PaintedScrollbarLayerImpl::PaintedScrollbarLayerImpl(
[email protected]3138b262013-03-08 18:39:0829 LayerTreeImpl* tree_impl,
30 int id,
[email protected]c28df4c12013-05-22 17:36:4931 ScrollbarOrientation orientation)
[email protected]adeda572014-01-31 00:49:4732 : ScrollbarLayerImplBase(tree_impl, id, orientation, false, false),
[email protected]45b46d382013-08-14 02:18:5833 track_ui_resource_id_(0),
34 thumb_ui_resource_id_(0),
[email protected]c28df4c12013-05-22 17:36:4935 thumb_thickness_(0),
36 thumb_length_(0),
37 track_start_(0),
38 track_length_(0),
[email protected]ffb2720f2013-03-15 19:18:3739 vertical_adjust_(0.f),
[email protected]80413d72013-08-30 20:25:3340 scroll_layer_id_(Layer::INVALID_ID) {}
[email protected]3138b262013-03-08 18:39:0841
[email protected]3a83478b2013-08-22 20:55:1742PaintedScrollbarLayerImpl::~PaintedScrollbarLayerImpl() {}
[email protected]3138b262013-03-08 18:39:0843
[email protected]3a83478b2013-08-22 20:55:1744scoped_ptr<LayerImpl> PaintedScrollbarLayerImpl::CreateLayerImpl(
[email protected]3138b262013-03-08 18:39:0845 LayerTreeImpl* tree_impl) {
danakjf446a072014-09-27 21:55:4846 return PaintedScrollbarLayerImpl::Create(tree_impl, id(), orientation());
[email protected]3138b262013-03-08 18:39:0847}
48
[email protected]3a83478b2013-08-22 20:55:1749void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
[email protected]80413d72013-08-30 20:25:3350 ScrollbarLayerImplBase::PushPropertiesTo(layer);
[email protected]3138b262013-03-08 18:39:0851
[email protected]3a83478b2013-08-22 20:55:1752 PaintedScrollbarLayerImpl* scrollbar_layer =
53 static_cast<PaintedScrollbarLayerImpl*>(layer);
[email protected]3138b262013-03-08 18:39:0854
[email protected]5493fc42013-08-15 01:46:2255 scrollbar_layer->SetThumbThickness(thumb_thickness_);
56 scrollbar_layer->SetThumbLength(thumb_length_);
57 scrollbar_layer->SetTrackStart(track_start_);
58 scrollbar_layer->SetTrackLength(track_length_);
[email protected]3138b262013-03-08 18:39:0859
[email protected]45b46d382013-08-14 02:18:5860 scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_);
61 scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_);
[email protected]3138b262013-03-08 18:39:0862}
63
[email protected]3a83478b2013-08-22 20:55:1764bool PaintedScrollbarLayerImpl::WillDraw(DrawMode draw_mode,
[email protected]ffbb2212013-06-02 23:47:5965 ResourceProvider* resource_provider) {
[email protected]80413d72013-08-30 20:25:3366 DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE);
[email protected]a877bc1382013-06-29 20:56:2067 return LayerImpl::WillDraw(draw_mode, resource_provider);
[email protected]ffbb2212013-06-02 23:47:5968}
69
[email protected]3a83478b2013-08-22 20:55:1770void PaintedScrollbarLayerImpl::AppendQuads(
[email protected]c6707fd2014-06-23 05:50:3671 RenderPass* render_pass,
vmpstr11b77b432014-10-07 20:11:4072 const Occlusion& occlusion_in_content_space,
[email protected]3a83478b2013-08-22 20:55:1773 AppendQuadsData* append_quads_data) {
[email protected]3138b262013-03-08 18:39:0874 bool premultipled_alpha = true;
75 bool flipped = false;
76 gfx::PointF uv_top_left(0.f, 0.f);
77 gfx::PointF uv_bottom_right(1.f, 1.f);
bokancccfde72014-10-08 15:15:2278 gfx::Rect bounds_rect(bounds());
[email protected]ed511b8d2013-03-25 03:29:2979 gfx::Rect content_bounds_rect(content_bounds());
[email protected]3138b262013-03-08 18:39:0880
[email protected]c6707fd2014-06-23 05:50:3681 SharedQuadState* shared_quad_state =
82 render_pass->CreateAndAppendSharedQuadState();
[email protected]9be1adc2014-05-07 15:39:4183 PopulateSharedQuadState(shared_quad_state);
84
[email protected]b48a0b12014-06-20 20:20:3285 AppendDebugBorderQuad(
[email protected]c6707fd2014-06-23 05:50:3686 render_pass, content_bounds(), shared_quad_state, append_quads_data);
[email protected]3138b262013-03-08 18:39:0887
[email protected]c28df4c12013-05-22 17:36:4988 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect();
vmpstr5b88d992014-09-18 23:25:0489 gfx::Rect visible_thumb_quad_rect =
vmpstr11b77b432014-10-07 20:11:4090 occlusion_in_content_space.GetUnoccludedContentRect(thumb_quad_rect);
[email protected]c28df4c12013-05-22 17:36:4991
[email protected]45b46d382013-08-14 02:18:5892 ResourceProvider::ResourceId thumb_resource_id =
93 layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_);
94 ResourceProvider::ResourceId track_resource_id =
95 layer_tree_impl()->ResourceIdForUIResource(track_ui_resource_id_);
96
[email protected]90963ef2014-04-17 18:03:2997 if (thumb_resource_id && !visible_thumb_quad_rect.IsEmpty()) {
[email protected]3138b262013-03-08 18:39:0898 gfx::Rect opaque_rect;
99 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
[email protected]f7030c32014-07-03 18:54:34100 TextureDrawQuad* quad =
101 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
[email protected]3138b262013-03-08 18:39:08102 quad->SetNew(shared_quad_state,
[email protected]c28df4c12013-05-22 17:36:49103 thumb_quad_rect,
[email protected]3138b262013-03-08 18:39:08104 opaque_rect,
[email protected]9bf06c72014-03-07 18:16:24105 visible_thumb_quad_rect,
[email protected]45b46d382013-08-14 02:18:58106 thumb_resource_id,
[email protected]3138b262013-03-08 18:39:08107 premultipled_alpha,
108 uv_top_left,
109 uv_bottom_right,
[email protected]d18b4d62013-07-12 05:33:49110 SK_ColorTRANSPARENT,
[email protected]3138b262013-03-08 18:39:08111 opacity,
112 flipped);
[email protected]3138b262013-03-08 18:39:08113 }
114
[email protected]45b46d382013-08-14 02:18:58115 gfx::Rect track_quad_rect = content_bounds_rect;
vmpstr5b88d992014-09-18 23:25:04116 gfx::Rect visible_track_quad_rect =
vmpstr11b77b432014-10-07 20:11:40117 occlusion_in_content_space.GetUnoccludedContentRect(track_quad_rect);
[email protected]90963ef2014-04-17 18:03:29118 if (track_resource_id && !visible_track_quad_rect.IsEmpty()) {
[email protected]45b46d382013-08-14 02:18:58119 gfx::Rect opaque_rect(contents_opaque() ? track_quad_rect : gfx::Rect());
[email protected]3138b262013-03-08 18:39:08120 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
[email protected]f7030c32014-07-03 18:54:34121 TextureDrawQuad* quad =
122 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
[email protected]3138b262013-03-08 18:39:08123 quad->SetNew(shared_quad_state,
[email protected]45b46d382013-08-14 02:18:58124 track_quad_rect,
[email protected]3138b262013-03-08 18:39:08125 opaque_rect,
[email protected]9bf06c72014-03-07 18:16:24126 visible_track_quad_rect,
[email protected]45b46d382013-08-14 02:18:58127 track_resource_id,
[email protected]3138b262013-03-08 18:39:08128 premultipled_alpha,
129 uv_top_left,
130 uv_bottom_right,
[email protected]d18b4d62013-07-12 05:33:49131 SK_ColorTRANSPARENT,
[email protected]3138b262013-03-08 18:39:08132 opacity,
133 flipped);
[email protected]3138b262013-03-08 18:39:08134 }
[email protected]94f206c12012-08-25 00:09:14135}
136
[email protected]3a83478b2013-08-22 20:55:17137void PaintedScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) {
[email protected]5493fc42013-08-15 01:46:22138 if (thumb_thickness_ == thumb_thickness)
139 return;
140 thumb_thickness_ = thumb_thickness;
141 NoteLayerPropertyChanged();
142}
143
[email protected]80413d72013-08-30 20:25:33144int PaintedScrollbarLayerImpl::ThumbThickness() const {
145 return thumb_thickness_;
146}
147
[email protected]3a83478b2013-08-22 20:55:17148void PaintedScrollbarLayerImpl::SetThumbLength(int thumb_length) {
[email protected]5493fc42013-08-15 01:46:22149 if (thumb_length_ == thumb_length)
150 return;
151 thumb_length_ = thumb_length;
152 NoteLayerPropertyChanged();
153}
[email protected]80413d72013-08-30 20:25:33154
155int PaintedScrollbarLayerImpl::ThumbLength() const {
156 return thumb_length_;
157}
158
[email protected]3a83478b2013-08-22 20:55:17159void PaintedScrollbarLayerImpl::SetTrackStart(int track_start) {
[email protected]5493fc42013-08-15 01:46:22160 if (track_start_ == track_start)
161 return;
162 track_start_ = track_start;
163 NoteLayerPropertyChanged();
164}
165
[email protected]80413d72013-08-30 20:25:33166int PaintedScrollbarLayerImpl::TrackStart() const {
167 return track_start_;
168}
169
[email protected]3a83478b2013-08-22 20:55:17170void PaintedScrollbarLayerImpl::SetTrackLength(int track_length) {
[email protected]5493fc42013-08-15 01:46:22171 if (track_length_ == track_length)
172 return;
173 track_length_ = track_length;
174 NoteLayerPropertyChanged();
175}
176
[email protected]80413d72013-08-30 20:25:33177float PaintedScrollbarLayerImpl::TrackLength() const {
178 return track_length_ + (orientation() == VERTICAL ? vertical_adjust() : 0);
[email protected]c28df4c12013-05-22 17:36:49179}
180
[email protected]41bee9f02014-01-09 01:11:35181bool PaintedScrollbarLayerImpl::IsThumbResizable() const {
182 return false;
183}
184
[email protected]3a83478b2013-08-22 20:55:17185const char* PaintedScrollbarLayerImpl::LayerTypeAsString() const {
186 return "cc::PaintedScrollbarLayerImpl";
[email protected]94f206c12012-08-25 00:09:14187}
[email protected]493067512012-09-19 23:34:10188
[email protected]bc5e77c2012-11-05 20:00:49189} // namespace cc