Chromium Code Reviews| Index: cc/hardcoded_scrollbar.cc |
| diff --git a/cc/hardcoded_scrollbar.cc b/cc/hardcoded_scrollbar.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..41ed4798e2606a15667cc4b9523d56e2359c6e6d |
| --- /dev/null |
| +++ b/cc/hardcoded_scrollbar.cc |
| @@ -0,0 +1,181 @@ |
| +// Copyright 2011 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/hardcoded_scrollbar.h" |
| + |
| +#include "cc/layer_impl.h" |
| +#include "cc/layer_tree_host_impl.h" |
| +#include "cc/layer_tree_impl.h" |
| +#include "cc/render_pass.h" |
| +#include "cc/shared_quad_state.h" |
| +#include "cc/solid_color_draw_quad.h" |
| +#include "ui/gfx/rect_conversions.h" |
| + |
| +namespace cc { |
| + |
| +#if defined(OS_ANDROID) |
| + |
| +static const int kScrollbarWidth = 8; |
| +static const int kScrollbarMargin = 5; |
| +static const int kFadeoutDelayMs = 300; |
| +static const int kFadeoutLengthMs = 300; |
| + |
| +HardcodedScrollbar::HardcodedScrollbar(LayerTreeHostImpl* layer_tree_host_impl) |
| + : layer_tree_host_impl_(layer_tree_host_impl) |
| + , opacity_(0) |
| + , pinch_in_effect_(false) |
| +{ |
| +} |
| + |
| +void HardcodedScrollbar::Animate(base::TimeTicks monotonic_time) |
| +{ |
| + if (!layer_tree_host_impl_->rootScrollLayer()) |
| + return; |
| + |
| + const base::TimeDelta fadeout_delay = |
| + base::TimeDelta::FromMilliseconds(kFadeoutDelayMs); |
| + const base::TimeDelta fadeout_length = |
| + base::TimeDelta::FromMilliseconds(kFadeoutLengthMs); |
| + |
| + if (pinch_in_effect_) |
| + last_awaken_time_ = monotonic_time; |
| + |
| + LayerImpl* scroll_layer = layer_tree_host_impl_->rootScrollLayer(); |
| + gfx::Vector2dF scroll_offset = scroll_layer->scrollOffset() + |
| + scroll_layer->scrollDelta(); |
| + |
| + if (last_scroll_offset_ != scroll_offset) { |
| + last_scroll_offset_ = scroll_offset; |
| + last_awaken_time_ = monotonic_time; |
| + } |
| + |
| + if (!last_awaken_time_.is_null() && |
| + last_awaken_time_ + fadeout_delay >= monotonic_time) |
| + opacity_ = 1; |
| + else if (!last_awaken_time_.is_null() && |
| + last_awaken_time_ + fadeout_delay + fadeout_length > monotonic_time) { |
| + opacity_ = (last_awaken_time_ + fadeout_delay + fadeout_length - |
| + monotonic_time).InMillisecondsF() / kFadeoutLengthMs; |
| + } else |
| + opacity_ = 0; |
| + |
| + if (opacity_) |
| + layer_tree_host_impl_->setNeedsRedraw(); |
| +} |
| + |
| +static void PrependRect(QuadList* quad_list, |
| + SharedQuadState* quad_state, |
| + const gfx::Rect& rect, |
| + const SkColor& color) |
| +{ |
| + scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); |
| + quad->SetAll(quad_state, |
| + rect, |
| + gfx::Rect(), |
| + rect, |
| + true, |
| + color); |
| + quad_list->insert(quad_list->begin(), |
| + quad.PassAs<DrawQuad>()); |
| +} |
| + |
| +static void PrependSmoothEdgedRect(QuadList* quad_list, |
| + SharedQuadState* quad_state, |
| + const gfx::Rect& rect, |
| + const SkColor& color) |
| +{ |
| + if (rect.width() < 2 || rect.height() < 2) |
| + return; |
| + |
| + SkColor half_color = SkColorSetA(color, SkColorGetA(color) / 2); |
| + |
| + gfx::Rect top_rect(rect.x() + 1, rect.y(), rect.width() - 2, 1); |
| + PrependRect(quad_list, quad_state, top_rect, half_color); |
| + gfx::Rect left_rect(rect.x(), rect.y() + 1, 1, rect.height() - 2); |
| + PrependRect(quad_list, quad_state, left_rect, half_color); |
| + gfx::Rect center_rect(rect.x() + 1, rect.y() + 1, |
| + rect.width() - 2, rect.height() - 2); |
| + PrependRect(quad_list, quad_state, center_rect, color); |
| + gfx::Rect right_rect(rect.right() - 1, rect.y() + 1, 1, rect.height() - 2); |
| + PrependRect(quad_list, quad_state, right_rect, half_color); |
| + gfx::Rect bottom_rect(rect.x() + 1, rect.bottom() - 1, rect.width() - 2, 1); |
| + PrependRect(quad_list, quad_state, bottom_rect, half_color); |
| +} |
| + |
| +void HardcodedScrollbar::PrependQuads(RenderPass* render_pass) |
| +{ |
|
danakj
2013/02/05 17:55:02
{ on previous line
|
| + if (!opacity_ || !layer_tree_host_impl_->rootScrollLayer()) |
| + return; |
| + |
| + gfx::Rect screen_rect(layer_tree_host_impl_->deviceViewportSize()); |
| + |
| + render_pass->shared_quad_state_list.push_back(SharedQuadState::Create()); |
| + SharedQuadState* quad_state = render_pass->shared_quad_state_list.back(); |
| + quad_state->SetAll(gfx::Transform(), |
| + screen_rect, |
| + screen_rect, |
| + false, |
| + opacity_); |
| + |
| + LayerImpl* scroll_layer = layer_tree_host_impl_->rootScrollLayer(); |
| + gfx::Size scrollable_size = |
| + layer_tree_host_impl_->activeTree()->ScrollableSize(); |
| + gfx::SizeF scrollable_viewport_size = |
| + layer_tree_host_impl_->activeTree()->ScrollableViewportSize(); |
| + |
| + gfx::RectF normalized_visible_content_rect = ScaleRect( |
| + gfx::RectF(gfx::PointF() + last_scroll_offset_, scrollable_viewport_size), |
| + 1.0 / scrollable_size.width(), |
| + 1.0 / scrollable_size.height()); |
| + normalized_visible_content_rect.Intersect(gfx::RectF(0, 0, 1, 1)); |
| + |
| + int scrollbar_width = kScrollbarWidth * |
| + layer_tree_host_impl_->deviceScaleFactor(); |
| + int scrollbar_margin = kScrollbarMargin * |
| + layer_tree_host_impl_->deviceScaleFactor(); |
| + |
| + gfx::Rect thumb_position = ToEnclosingRect(ScaleRect( |
| + normalized_visible_content_rect, |
| + screen_rect.width() - scrollbar_margin * 4 - scrollbar_width, |
| + screen_rect.height() - 2 * scrollbar_margin)); |
| + thumb_position.Offset(scrollbar_margin, scrollbar_margin); |
| + |
| + gfx::Rect horizontal_scrollbar_rect( |
| + thumb_position.x(), |
| + screen_rect.bottom() - scrollbar_margin - scrollbar_width, |
| + thumb_position.width(), |
| + scrollbar_width); |
| + PrependSmoothEdgedRect(&render_pass->quad_list, quad_state, |
| + horizontal_scrollbar_rect, SkColorSetARGB(128, 128, 128, 128)); |
| + |
| + gfx::Rect vertical_scrollbar_rect( |
| + screen_rect.right() - scrollbar_margin - scrollbar_width, |
| + thumb_position.y(), |
| + scrollbar_width, |
| + thumb_position.height()); |
| + PrependSmoothEdgedRect(&render_pass->quad_list, quad_state, |
| + vertical_scrollbar_rect, SkColorSetARGB(128, 128, 128, 128)); |
| +} |
| + |
| +void HardcodedScrollbar::DidPinchGestureUpdate(base::TimeTicks monotonic_time) |
| +{ |
| + pinch_in_effect_ = true; |
| + Animate(monotonic_time); |
| +} |
| + |
| +void HardcodedScrollbar::DidPinchGestureEnd(base::TimeTicks monotonic_time) |
| +{ |
| + pinch_in_effect_ = false; |
| + last_awaken_time_ = monotonic_time; |
| + Animate(monotonic_time); |
| +} |
| + |
| +void HardcodedScrollbar::DidUpdateScrollOffset(base::TimeTicks monotonic_time) |
| +{ |
| + Animate(monotonic_time); |
| +} |
| + |
| +#endif |
| + |
| +} // namespace cc |