Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: Source/core/platform/Scrollbar.cpp

Issue 16982005: Allow objects without scrollbars to be scrollable (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: CR fixes Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #define THUMB_POSITION_AFFECTS_BUTTONS 48 #define THUMB_POSITION_AFFECTS_BUTTONS
49 #endif 49 #endif
50 50
51 namespace WebCore { 51 namespace WebCore {
52 52
53 PassRefPtr<Scrollbar> Scrollbar::createNativeScrollbar(ScrollableArea* scrollabl eArea, ScrollbarOrientation orientation, ScrollbarControlSize size) 53 PassRefPtr<Scrollbar> Scrollbar::createNativeScrollbar(ScrollableArea* scrollabl eArea, ScrollbarOrientation orientation, ScrollbarControlSize size)
54 { 54 {
55 return adoptRef(new Scrollbar(scrollableArea, orientation, size)); 55 return adoptRef(new Scrollbar(scrollableArea, orientation, size));
56 } 56 }
57 57
58 int Scrollbar::maxOverlapBetweenPages()
59 {
60 static int maxOverlapBetweenPages = ScrollbarTheme::theme()->maxOverlapBetwe enPages();
61 return maxOverlapBetweenPages;
62 }
63
64 Scrollbar::Scrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orient ation, ScrollbarControlSize controlSize, 58 Scrollbar::Scrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orient ation, ScrollbarControlSize controlSize,
65 ScrollbarTheme* theme) 59 ScrollbarTheme* theme)
66 : m_scrollableArea(scrollableArea) 60 : m_scrollableArea(scrollableArea)
67 , m_orientation(orientation) 61 , m_orientation(orientation)
68 , m_controlSize(controlSize) 62 , m_controlSize(controlSize)
69 , m_theme(theme) 63 , m_theme(theme)
70 , m_visibleSize(0) 64 , m_visibleSize(0)
71 , m_totalSize(0) 65 , m_totalSize(0)
72 , m_currentPos(0) 66 , m_currentPos(0)
73 , m_dragOrigin(0) 67 , m_dragOrigin(0)
74 , m_lineStep(0)
75 , m_pageStep(0)
76 , m_pixelStep(1)
77 , m_hoveredPart(NoPart) 68 , m_hoveredPart(NoPart)
78 , m_pressedPart(NoPart) 69 , m_pressedPart(NoPart)
79 , m_pressedPos(0) 70 , m_pressedPos(0)
80 , m_scrollPos(0) 71 , m_scrollPos(0)
81 , m_draggingDocument(false) 72 , m_draggingDocument(false)
82 , m_documentDragPos(0) 73 , m_documentDragPos(0)
83 , m_enabled(true) 74 , m_enabled(true)
84 , m_scrollTimer(this, &Scrollbar::autoscrollTimerFired) 75 , m_scrollTimer(this, &Scrollbar::autoscrollTimerFired)
85 , m_overlapsResizer(false) 76 , m_overlapsResizer(false)
86 , m_suppressInvalidation(false) 77 , m_suppressInvalidation(false)
87 , m_isAlphaLocked(false) 78 , m_isAlphaLocked(false)
88 { 79 {
89 if (!m_theme) 80 if (!m_theme)
90 m_theme = ScrollbarTheme::theme(); 81 m_theme = ScrollbarTheme::theme();
91 82
92 m_theme->registerScrollbar(this); 83 m_theme->registerScrollbar(this);
93 84
94 // FIXME: This is ugly and would not be necessary if we fix cross-platform c ode to actually query for 85 // FIXME: This is ugly and would not be necessary if we fix cross-platform c ode to actually query for
95 // scrollbar thickness and use it when sizing scrollbars (rather than leavin g one dimension of the scrollbar 86 // scrollbar thickness and use it when sizing scrollbars (rather than leavin g one dimension of the scrollbar
96 // alone when sizing). 87 // alone when sizing).
97 int thickness = m_theme->scrollbarThickness(controlSize); 88 int thickness = m_theme->scrollbarThickness(controlSize);
98 Widget::setFrameRect(IntRect(0, 0, thickness, thickness)); 89 Widget::setFrameRect(IntRect(0, 0, thickness, thickness));
99 90
100 if (m_scrollableArea) 91 m_currentPos = scrollableAreaCurrentPos();
101 m_currentPos = static_cast<float>(m_scrollableArea->scrollPosition(this) );
102 } 92 }
103 93
104 Scrollbar::~Scrollbar() 94 Scrollbar::~Scrollbar()
105 { 95 {
106 if (AXObjectCache* cache = existingAXObjectCache()) 96 if (AXObjectCache* cache = existingAXObjectCache())
107 cache->remove(this); 97 cache->remove(this);
108 98
109 stopTimerIfNeeded(); 99 stopTimerIfNeeded();
110 100
111 m_theme->unregisterScrollbar(this); 101 m_theme->unregisterScrollbar(this);
(...skipping 17 matching lines...) Expand all
129 119
130 bool Scrollbar::isScrollViewScrollbar() const 120 bool Scrollbar::isScrollViewScrollbar() const
131 { 121 {
132 return parent() && parent()->isFrameView() && toFrameView(parent())->isScrol lViewScrollbar(this); 122 return parent() && parent()->isFrameView() && toFrameView(parent())->isScrol lViewScrollbar(this);
133 } 123 }
134 124
135 void Scrollbar::offsetDidChange() 125 void Scrollbar::offsetDidChange()
136 { 126 {
137 ASSERT(m_scrollableArea); 127 ASSERT(m_scrollableArea);
138 128
139 float position = static_cast<float>(m_scrollableArea->scrollPosition(this)); 129 float position = scrollableAreaCurrentPos();
140 if (position == m_currentPos) 130 if (position == m_currentPos)
141 return; 131 return;
142 132
143 int oldThumbPosition = theme()->thumbPosition(this); 133 int oldThumbPosition = theme()->thumbPosition(this);
144 m_currentPos = position; 134 m_currentPos = position;
145 updateThumbPosition(); 135 updateThumbPosition();
146 if (m_pressedPart == ThumbPart) 136 if (m_pressedPart == ThumbPart)
147 setPressedPos(m_pressedPos + theme()->thumbPosition(this) - oldThumbPosi tion); 137 setPressedPos(m_pressedPos + theme()->thumbPosition(this) - oldThumbPosi tion);
148 } 138 }
149 139
150 void Scrollbar::setProportion(int visibleSize, int totalSize) 140 void Scrollbar::setProportion(int visibleSize, int totalSize)
151 { 141 {
152 if (visibleSize == m_visibleSize && totalSize == m_totalSize) 142 if (visibleSize == m_visibleSize && totalSize == m_totalSize)
153 return; 143 return;
154 144
155 m_visibleSize = visibleSize; 145 m_visibleSize = visibleSize;
156 m_totalSize = totalSize; 146 m_totalSize = totalSize;
157 147
158 updateThumbProportion(); 148 updateThumbProportion();
159 } 149 }
160 150
161 void Scrollbar::setSteps(int lineStep, int pageStep, int pixelsPerStep)
162 {
163 m_lineStep = lineStep;
164 m_pageStep = pageStep;
165 m_pixelStep = 1.0f / pixelsPerStep;
166 }
167
168 void Scrollbar::updateThumb() 151 void Scrollbar::updateThumb()
169 { 152 {
170 #ifdef THUMB_POSITION_AFFECTS_BUTTONS 153 #ifdef THUMB_POSITION_AFFECTS_BUTTONS
171 invalidate(); 154 invalidate();
172 #else 155 #else
173 theme()->invalidateParts(this, ForwardTrackPart | BackTrackPart | ThumbPart) ; 156 theme()->invalidateParts(this, ForwardTrackPart | BackTrackPart | ThumbPart) ;
174 #endif 157 #endif
175 } 158 }
176 159
177 void Scrollbar::updateThumbPosition() 160 void Scrollbar::updateThumbPosition()
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 577 }
595 578
596 IntPoint Scrollbar::convertFromContainingView(const IntPoint& parentPoint) const 579 IntPoint Scrollbar::convertFromContainingView(const IntPoint& parentPoint) const
597 { 580 {
598 if (m_scrollableArea) 581 if (m_scrollableArea)
599 return m_scrollableArea->convertFromContainingViewToScrollbar(this, pare ntPoint); 582 return m_scrollableArea->convertFromContainingViewToScrollbar(this, pare ntPoint);
600 583
601 return Widget::convertFromContainingView(parentPoint); 584 return Widget::convertFromContainingView(parentPoint);
602 } 585 }
603 586
587 float Scrollbar::scrollableAreaCurrentPos() const
588 {
589 if (!m_scrollableArea)
590 return 0;
591
592 if (m_orientation == HorizontalScrollbar)
593 return m_scrollableArea->scrollPosition().x() + m_scrollableArea->scroll Origin().x();
trchen 2013/06/20 01:46:43 I recommend phasing out scrollOrigin(). Please use
bokan 2013/06/20 19:00:16 Done.
594
595 return m_scrollableArea->scrollPosition().y() + m_scrollableArea->scrollOrig in().y();
596 }
597
604 } // namespace WebCore 598 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698