solid_color_scrollbar_layer.cc 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2013 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. #include "cc/layers/solid_color_scrollbar_layer.h"
  5. #include <memory>
  6. #include "cc/layers/layer_impl.h"
  7. #include "cc/layers/solid_color_scrollbar_layer_impl.h"
  8. namespace cc {
  9. std::unique_ptr<LayerImpl> SolidColorScrollbarLayer::CreateLayerImpl(
  10. LayerTreeImpl* tree_impl) const {
  11. return SolidColorScrollbarLayerImpl::Create(
  12. tree_impl, id(), orientation(), thumb_thickness_, track_start_,
  13. is_left_side_vertical_scrollbar());
  14. }
  15. scoped_refptr<SolidColorScrollbarLayer> SolidColorScrollbarLayer::CreateOrReuse(
  16. scoped_refptr<Scrollbar> scrollbar,
  17. SolidColorScrollbarLayer* existing_layer) {
  18. DCHECK(scrollbar->IsOverlay());
  19. bool is_horizontal =
  20. scrollbar->Orientation() == ScrollbarOrientation::HORIZONTAL;
  21. gfx::Rect thumb_rect = scrollbar->ThumbRect();
  22. int thumb_thickness =
  23. is_horizontal ? thumb_rect.height() : thumb_rect.width();
  24. gfx::Rect track_rect = scrollbar->TrackRect();
  25. int track_start = is_horizontal ? track_rect.x() : track_rect.y();
  26. if (existing_layer &&
  27. // We don't support change of these fields in a layer.
  28. existing_layer->thumb_thickness() == thumb_thickness &&
  29. existing_layer->track_start() == track_start) {
  30. // These fields have been checked in ScrollbarLayerBase::CreateOrReuse().
  31. DCHECK_EQ(scrollbar->Orientation(), existing_layer->orientation());
  32. DCHECK_EQ(scrollbar->IsLeftSideVerticalScrollbar(),
  33. existing_layer->is_left_side_vertical_scrollbar());
  34. return existing_layer;
  35. }
  36. return Create(scrollbar->Orientation(), thumb_thickness, track_start,
  37. scrollbar->IsLeftSideVerticalScrollbar());
  38. }
  39. scoped_refptr<SolidColorScrollbarLayer> SolidColorScrollbarLayer::Create(
  40. ScrollbarOrientation orientation,
  41. int thumb_thickness,
  42. int track_start,
  43. bool is_left_side_vertical_scrollbar) {
  44. return base::WrapRefCounted(
  45. new SolidColorScrollbarLayer(orientation, thumb_thickness, track_start,
  46. is_left_side_vertical_scrollbar));
  47. }
  48. SolidColorScrollbarLayer::SolidColorScrollbarLayer(
  49. ScrollbarOrientation orientation,
  50. int thumb_thickness,
  51. int track_start,
  52. bool is_left_side_vertical_scrollbar)
  53. : ScrollbarLayerBase(orientation, is_left_side_vertical_scrollbar),
  54. thumb_thickness_(thumb_thickness),
  55. track_start_(track_start) {
  56. Layer::SetOpacity(0.f);
  57. }
  58. SolidColorScrollbarLayer::~SolidColorScrollbarLayer() = default;
  59. void SolidColorScrollbarLayer::SetOpacity(float opacity) {
  60. // The opacity of a solid color scrollbar layer is always 0 on main thread.
  61. DCHECK_EQ(opacity, 0.f);
  62. Layer::SetOpacity(opacity);
  63. }
  64. void SolidColorScrollbarLayer::SetNeedsDisplayRect(const gfx::Rect& rect) {}
  65. bool SolidColorScrollbarLayer::OpacityCanAnimateOnImplThread() const {
  66. return true;
  67. }
  68. bool SolidColorScrollbarLayer::HitTestable() const {
  69. // Android scrollbars can't be interacted with by user input. They should
  70. // avoid hit testing so we don't enter any scrollbar scrolling code paths.
  71. return false;
  72. }
  73. ScrollbarLayerBase::ScrollbarLayerType
  74. SolidColorScrollbarLayer::GetScrollbarLayerType() const {
  75. return kSolidColor;
  76. }
  77. } // namespace cc