Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 5 #include "cc/pinch_zoom_scrollbar_geometry.h" | |
| 6 | |
| 7 #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" | |
| 8 | |
| 9 namespace cc { | |
| 10 | |
| 11 const int PinchZoomScrollbarGeometry::kTrackWidth = 10; | |
| 12 | |
| 13 WebScrollbarThemeGeometry* PinchZoomScrollbarGeometry::clone() const { | |
| 14 return static_cast<WebScrollbarThemeGeometry*>( | |
| 15 new PinchZoomScrollbarGeometry()); | |
| 16 } | |
| 17 | |
| 18 int PinchZoomScrollbarGeometry::thumbPosition(WebScrollbar* scrollbar) { | |
| 19 if (scrollbar->enabled()) { | |
| 20 float max_value = scrollbar->maximum(); | |
| 21 if (!max_value) | |
| 22 return 1; | |
| 23 int value = std::min(std::max(0, scrollbar->value()), scrollbar->maximum()); | |
| 24 float pos = (trackLength(scrollbar) - thumbLength(scrollbar)) * | |
| 25 value / max_value; | |
| 26 return static_cast<int>(floorf((pos > 0 && pos < 1) ? 1 : pos)); | |
| 27 } | |
| 28 return 0; | |
| 29 } | |
| 30 | |
| 31 int PinchZoomScrollbarGeometry::thumbLength(WebScrollbar* scrollbar) { | |
| 32 if (!scrollbar->enabled()) | |
| 33 return 0; | |
| 34 | |
| 35 float size = std::max(scrollbar->size().width, scrollbar->size().height); | |
| 36 float proportion = size / scrollbar->totalSize(); | |
| 37 int track_length = this->trackLength(scrollbar); | |
| 38 int length = proportion * track_length + 0.5f; | |
| 39 length = std::max(length, kTrackWidth); | |
| 40 if (length > track_length) | |
| 41 length = 0; | |
| 42 return length; | |
| 43 } | |
| 44 | |
| 45 int PinchZoomScrollbarGeometry::trackPosition(WebScrollbar*) { | |
| 46 return 0; | |
| 47 } | |
| 48 | |
| 49 int PinchZoomScrollbarGeometry::trackLength(WebScrollbar* scrollbar) { | |
| 50 WebRect track = trackRect(scrollbar); | |
| 51 if (scrollbar->orientation() == WebScrollbar::Horizontal) | |
| 52 return track.width; | |
| 53 else | |
| 54 return track.height; | |
| 55 } | |
| 56 | |
| 57 bool PinchZoomScrollbarGeometry::hasButtons(WebScrollbar*) { | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 bool PinchZoomScrollbarGeometry::hasThumb(WebScrollbar*) { | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 WebRect PinchZoomScrollbarGeometry::trackRect(WebScrollbar* scrollbar) { | |
| 66 int thickness = scrollbarThickness(scrollbar); | |
| 67 if (scrollbar->orientation() == WebScrollbar::Horizontal) | |
| 68 return WebRect(scrollbar->location().x, scrollbar->location().y, | |
| 69 scrollbar->size().width, thickness); | |
| 70 else | |
| 71 return WebRect(scrollbar->location().x, scrollbar->location().y, | |
| 72 thickness, scrollbar->size().height); | |
| 73 } | |
| 74 | |
| 75 WebRect PinchZoomScrollbarGeometry::thumbRect(WebScrollbar* scrollbar) { | |
| 76 WebRect track = trackRect(scrollbar); | |
| 77 int thumb_pos = thumbPosition(scrollbar); | |
| 78 int thickness = scrollbarThickness(scrollbar); | |
| 79 if (scrollbar->orientation() == WebScrollbar::Horizontal) | |
| 80 return WebRect(track.x + thumb_pos, track.y + (track.height - thickness) / | |
|
enne (OOO)
2013/03/11 21:08:24
style nit: use braces for multiline statements.
wjmaclean
2013/03/12 16:13:07
Done.
| |
| 81 2, thumbLength(scrollbar), thickness); | |
| 82 else | |
| 83 return WebRect(track.x + (track.width - thickness) / 2, track.y + thumb_pos, | |
| 84 thickness, thumbLength(scrollbar)); | |
| 85 } | |
| 86 | |
| 87 int PinchZoomScrollbarGeometry::minimumThumbLength(WebScrollbar* scrollbar) { | |
| 88 return scrollbarThickness(scrollbar); | |
| 89 } | |
| 90 | |
| 91 int PinchZoomScrollbarGeometry::scrollbarThickness(WebScrollbar*) { | |
| 92 return kTrackWidth; | |
| 93 } | |
| 94 | |
| 95 WebRect PinchZoomScrollbarGeometry::backButtonStartRect(WebScrollbar*) { | |
| 96 return WebRect(); | |
| 97 } | |
| 98 | |
| 99 WebRect PinchZoomScrollbarGeometry::backButtonEndRect(WebScrollbar*) { | |
| 100 return WebRect(); | |
| 101 } | |
| 102 | |
| 103 WebRect PinchZoomScrollbarGeometry::forwardButtonStartRect(WebScrollbar*) { | |
| 104 return WebRect(); | |
| 105 } | |
| 106 | |
| 107 WebRect PinchZoomScrollbarGeometry::forwardButtonEndRect(WebScrollbar*) { | |
| 108 return WebRect(); | |
| 109 } | |
| 110 | |
| 111 WebRect PinchZoomScrollbarGeometry::constrainTrackRectToTrackPieces( | |
| 112 WebScrollbar*, const WebRect& rect) { | |
| 113 return rect; | |
| 114 } | |
| 115 | |
| 116 void PinchZoomScrollbarGeometry::splitTrack( | |
| 117 WebScrollbar* scrollbar, const WebRect& track, WebRect& start_track, | |
| 118 WebRect& thumb, WebRect& end_track) { | |
| 119 thumb = thumbRect(scrollbar); | |
| 120 start_track = WebRect(); | |
| 121 end_track = WebRect(); | |
| 122 } | |
| 123 | |
| 124 } // namespace cc | |
| OLD | NEW |