summaryrefslogtreecommitdiffstats
path: root/cc/input/pinch_zoom_scrollbar.cc
blob: e28781011b9517e6a8a366a49acc517cb8ddd009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2013 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/input/pinch_zoom_scrollbar.h"

#include "cc/input/pinch_zoom_scrollbar_geometry.h"
#include "cc/layers/layer.h"
#include "cc/trees/layer_tree_host.h"

namespace cc {

const float PinchZoomScrollbar::kDefaultOpacity = 0.5f;
const float PinchZoomScrollbar::kFadeDurationInSeconds = 0.5f;

PinchZoomScrollbar::PinchZoomScrollbar(
    WebKit::WebScrollbar::Orientation orientation, LayerTreeHost* owner)
  : orientation_(orientation),
    owner_(owner) {
  DCHECK(owner_);
}


bool PinchZoomScrollbar::isOverlay() const { return true; }

int PinchZoomScrollbar::value() const {
  const Layer* root_scroll_layer = owner_->RootScrollLayer();
  if (!root_scroll_layer)
    return 0;

  if (orientation_ == WebKit::WebScrollbar::Horizontal)
    return root_scroll_layer->scroll_offset().x();
  else
    return root_scroll_layer->scroll_offset().y();
}

WebKit::WebPoint PinchZoomScrollbar::location() const {
  return WebKit::WebPoint();
}

WebKit::WebSize PinchZoomScrollbar::size() const {
  gfx::Size viewport_size = owner_->layout_viewport_size();
  gfx::Size size;
  int track_width = PinchZoomScrollbarGeometry::kTrackWidth;
  if (orientation_ == WebKit::WebScrollbar::Horizontal)
    size = gfx::Size(viewport_size.width() - track_width, track_width);
  else
    size = gfx::Size(track_width, viewport_size.height() - track_width);
  return WebKit::WebSize(size);
}

bool PinchZoomScrollbar::enabled() const {
  return true;
}

int PinchZoomScrollbar::maximum() const {
  const Layer* root_scroll_layer = owner_->RootScrollLayer();
  if (!root_scroll_layer)
    return 0;

  gfx::Size device_viewport_size = owner_->device_viewport_size();
  gfx::Size root_scroll_bounds = root_scroll_layer->content_bounds();

  if (orientation_ == WebKit::WebScrollbar::Horizontal)
    return root_scroll_bounds.width() - device_viewport_size.width();
  else
    return root_scroll_bounds.height() - device_viewport_size.height();
}

int PinchZoomScrollbar::totalSize() const {
  const Layer* root_scroll_layer = owner_->RootScrollLayer();
  gfx::Size size;
  if (root_scroll_layer)
    size = root_scroll_layer->content_bounds();
  else
    size = gfx::Size();

  if (orientation_ == WebKit::WebScrollbar::Horizontal)
    return size.width();
  else
    return size.height();
}

bool PinchZoomScrollbar::isScrollViewScrollbar() const {
  return false;
}

bool PinchZoomScrollbar::isScrollableAreaActive() const {
  return true;
}

WebKit::WebScrollbar::ScrollbarControlSize PinchZoomScrollbar::controlSize()
    const {
  return WebKit::WebScrollbar::SmallScrollbar;
}

WebKit::WebScrollbar::ScrollbarPart PinchZoomScrollbar::pressedPart() const {
  return WebKit::WebScrollbar::NoPart;
}

WebKit::WebScrollbar::ScrollbarPart PinchZoomScrollbar::hoveredPart() const {
  return WebKit::WebScrollbar::NoPart;
}

WebKit::WebScrollbar::ScrollbarOverlayStyle
PinchZoomScrollbar::scrollbarOverlayStyle() const {
  return WebKit::WebScrollbar::ScrollbarOverlayStyleDefault;
}
bool PinchZoomScrollbar::isCustomScrollbar() const {
  return false;
}

WebKit::WebScrollbar::Orientation PinchZoomScrollbar::orientation() const {
  return orientation_;
}

}  // namespace cc