Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/hardcoded_scrollbar.h" | |
| 6 | |
| 7 #include "cc/layer_impl.h" | |
| 8 #include "cc/layer_tree_host_impl.h" | |
| 9 #include "cc/layer_tree_impl.h" | |
| 10 #include "cc/render_pass.h" | |
| 11 #include "cc/shared_quad_state.h" | |
| 12 #include "cc/solid_color_draw_quad.h" | |
| 13 #include "ui/gfx/rect_conversions.h" | |
| 14 | |
| 15 namespace cc { | |
| 16 | |
| 17 #if defined(OS_ANDROID) | |
| 18 | |
| 19 static const int kScrollbarWidth = 8; | |
| 20 static const int kScrollbarMargin = 5; | |
| 21 static const int kFadeoutDelayMs = 300; | |
| 22 static const int kFadeoutLengthMs = 300; | |
| 23 | |
| 24 HardcodedScrollbar::HardcodedScrollbar(LayerTreeHostImpl* layer_tree_host_impl) | |
| 25 : layer_tree_host_impl_(layer_tree_host_impl) | |
| 26 , opacity_(0) | |
| 27 , pinch_in_effect_(false) | |
| 28 { | |
| 29 } | |
| 30 | |
| 31 void HardcodedScrollbar::Animate(base::TimeTicks monotonic_time) | |
| 32 { | |
| 33 if (!layer_tree_host_impl_->rootScrollLayer()) | |
| 34 return; | |
| 35 | |
| 36 const base::TimeDelta fadeout_delay = | |
| 37 base::TimeDelta::FromMilliseconds(kFadeoutDelayMs); | |
| 38 const base::TimeDelta fadeout_length = | |
| 39 base::TimeDelta::FromMilliseconds(kFadeoutLengthMs); | |
| 40 | |
| 41 if (pinch_in_effect_) | |
| 42 last_awaken_time_ = monotonic_time; | |
| 43 | |
| 44 LayerImpl* scroll_layer = layer_tree_host_impl_->rootScrollLayer(); | |
| 45 gfx::Vector2dF scroll_offset = scroll_layer->scrollOffset() + | |
| 46 scroll_layer->scrollDelta(); | |
| 47 | |
| 48 if (last_scroll_offset_ != scroll_offset) { | |
| 49 last_scroll_offset_ = scroll_offset; | |
| 50 last_awaken_time_ = monotonic_time; | |
| 51 } | |
| 52 | |
| 53 if (!last_awaken_time_.is_null() && | |
| 54 last_awaken_time_ + fadeout_delay >= monotonic_time) | |
| 55 opacity_ = 1; | |
| 56 else if (!last_awaken_time_.is_null() && | |
| 57 last_awaken_time_ + fadeout_delay + fadeout_length > monotonic_time) { | |
| 58 opacity_ = (last_awaken_time_ + fadeout_delay + fadeout_length - | |
| 59 monotonic_time).InMillisecondsF() / kFadeoutLengthMs; | |
| 60 } else | |
| 61 opacity_ = 0; | |
| 62 | |
| 63 if (opacity_) | |
| 64 layer_tree_host_impl_->setNeedsRedraw(); | |
| 65 } | |
| 66 | |
| 67 static void PrependRect(QuadList* quad_list, | |
| 68 SharedQuadState* quad_state, | |
| 69 const gfx::Rect& rect, | |
| 70 const SkColor& color) | |
| 71 { | |
| 72 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); | |
| 73 quad->SetAll(quad_state, | |
| 74 rect, | |
| 75 gfx::Rect(), | |
| 76 rect, | |
| 77 true, | |
| 78 color); | |
| 79 quad_list->insert(quad_list->begin(), | |
| 80 quad.PassAs<DrawQuad>()); | |
| 81 } | |
| 82 | |
| 83 static void PrependSmoothEdgedRect(QuadList* quad_list, | |
| 84 SharedQuadState* quad_state, | |
| 85 const gfx::Rect& rect, | |
| 86 const SkColor& color) | |
| 87 { | |
| 88 if (rect.width() < 2 || rect.height() < 2) | |
| 89 return; | |
| 90 | |
| 91 SkColor half_color = SkColorSetA(color, SkColorGetA(color) / 2); | |
| 92 | |
| 93 gfx::Rect top_rect(rect.x() + 1, rect.y(), rect.width() - 2, 1); | |
| 94 PrependRect(quad_list, quad_state, top_rect, half_color); | |
| 95 gfx::Rect left_rect(rect.x(), rect.y() + 1, 1, rect.height() - 2); | |
| 96 PrependRect(quad_list, quad_state, left_rect, half_color); | |
| 97 gfx::Rect center_rect(rect.x() + 1, rect.y() + 1, | |
| 98 rect.width() - 2, rect.height() - 2); | |
| 99 PrependRect(quad_list, quad_state, center_rect, color); | |
| 100 gfx::Rect right_rect(rect.right() - 1, rect.y() + 1, 1, rect.height() - 2); | |
| 101 PrependRect(quad_list, quad_state, right_rect, half_color); | |
| 102 gfx::Rect bottom_rect(rect.x() + 1, rect.bottom() - 1, rect.width() - 2, 1); | |
| 103 PrependRect(quad_list, quad_state, bottom_rect, half_color); | |
| 104 } | |
| 105 | |
| 106 void HardcodedScrollbar::PrependQuads(RenderPass* render_pass) | |
| 107 { | |
|
danakj
2013/02/05 17:55:02
{ on previous line
| |
| 108 if (!opacity_ || !layer_tree_host_impl_->rootScrollLayer()) | |
| 109 return; | |
| 110 | |
| 111 gfx::Rect screen_rect(layer_tree_host_impl_->deviceViewportSize()); | |
| 112 | |
| 113 render_pass->shared_quad_state_list.push_back(SharedQuadState::Create()); | |
| 114 SharedQuadState* quad_state = render_pass->shared_quad_state_list.back(); | |
| 115 quad_state->SetAll(gfx::Transform(), | |
| 116 screen_rect, | |
| 117 screen_rect, | |
| 118 false, | |
| 119 opacity_); | |
| 120 | |
| 121 LayerImpl* scroll_layer = layer_tree_host_impl_->rootScrollLayer(); | |
| 122 gfx::Size scrollable_size = | |
| 123 layer_tree_host_impl_->activeTree()->ScrollableSize(); | |
| 124 gfx::SizeF scrollable_viewport_size = | |
| 125 layer_tree_host_impl_->activeTree()->ScrollableViewportSize(); | |
| 126 | |
| 127 gfx::RectF normalized_visible_content_rect = ScaleRect( | |
| 128 gfx::RectF(gfx::PointF() + last_scroll_offset_, scrollable_viewport_size), | |
| 129 1.0 / scrollable_size.width(), | |
| 130 1.0 / scrollable_size.height()); | |
| 131 normalized_visible_content_rect.Intersect(gfx::RectF(0, 0, 1, 1)); | |
| 132 | |
| 133 int scrollbar_width = kScrollbarWidth * | |
| 134 layer_tree_host_impl_->deviceScaleFactor(); | |
| 135 int scrollbar_margin = kScrollbarMargin * | |
| 136 layer_tree_host_impl_->deviceScaleFactor(); | |
| 137 | |
| 138 gfx::Rect thumb_position = ToEnclosingRect(ScaleRect( | |
| 139 normalized_visible_content_rect, | |
| 140 screen_rect.width() - scrollbar_margin * 4 - scrollbar_width, | |
| 141 screen_rect.height() - 2 * scrollbar_margin)); | |
| 142 thumb_position.Offset(scrollbar_margin, scrollbar_margin); | |
| 143 | |
| 144 gfx::Rect horizontal_scrollbar_rect( | |
| 145 thumb_position.x(), | |
| 146 screen_rect.bottom() - scrollbar_margin - scrollbar_width, | |
| 147 thumb_position.width(), | |
| 148 scrollbar_width); | |
| 149 PrependSmoothEdgedRect(&render_pass->quad_list, quad_state, | |
| 150 horizontal_scrollbar_rect, SkColorSetARGB(128, 128, 128, 128)); | |
| 151 | |
| 152 gfx::Rect vertical_scrollbar_rect( | |
| 153 screen_rect.right() - scrollbar_margin - scrollbar_width, | |
| 154 thumb_position.y(), | |
| 155 scrollbar_width, | |
| 156 thumb_position.height()); | |
| 157 PrependSmoothEdgedRect(&render_pass->quad_list, quad_state, | |
| 158 vertical_scrollbar_rect, SkColorSetARGB(128, 128, 128, 128)); | |
| 159 } | |
| 160 | |
| 161 void HardcodedScrollbar::DidPinchGestureUpdate(base::TimeTicks monotonic_time) | |
| 162 { | |
| 163 pinch_in_effect_ = true; | |
| 164 Animate(monotonic_time); | |
| 165 } | |
| 166 | |
| 167 void HardcodedScrollbar::DidPinchGestureEnd(base::TimeTicks monotonic_time) | |
| 168 { | |
| 169 pinch_in_effect_ = false; | |
| 170 last_awaken_time_ = monotonic_time; | |
| 171 Animate(monotonic_time); | |
| 172 } | |
| 173 | |
| 174 void HardcodedScrollbar::DidUpdateScrollOffset(base::TimeTicks monotonic_time) | |
| 175 { | |
| 176 Animate(monotonic_time); | |
| 177 } | |
| 178 | |
| 179 #endif | |
| 180 | |
| 181 } // namespace cc | |
| OLD | NEW |