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

Side by Side Diff: content/browser/accessibility/browser_accessibility.cc

Issue 8770021: Initial implementation of IAccessible2 scrollTo and setTextSelection and (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/accessibility/browser_accessibility.h" 5 #include "content/browser/accessibility/browser_accessibility.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "content/browser/accessibility/browser_accessibility_manager.h" 10 #include "content/browser/accessibility/browser_accessibility_manager.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Walk the children recursively looking for the BrowserAccessibility that 156 // Walk the children recursively looking for the BrowserAccessibility that
157 // most tightly encloses the specified point. 157 // most tightly encloses the specified point.
158 for (int i = children_.size() - 1; i >= 0; --i) { 158 for (int i = children_.size() - 1; i >= 0; --i) {
159 BrowserAccessibility* child = children_[i]; 159 BrowserAccessibility* child = children_[i];
160 if (child->GetGlobalBoundsRect().Contains(point)) 160 if (child->GetGlobalBoundsRect().Contains(point))
161 return child->BrowserAccessibilityForPoint(point); 161 return child->BrowserAccessibilityForPoint(point);
162 } 162 }
163 return this; 163 return this;
164 } 164 }
165 165
166 void BrowserAccessibility::ScrollToMakeVisible(const gfx::Rect& subfocus,
167 const gfx::Rect& focus,
168 const gfx::Rect& viewport) {
169 int scroll_x = 0;
170 int scroll_x_min = 0;
171 int scroll_x_max = 0;
172 int scroll_y = 0;
173 int scroll_y_min = 0;
174 int scroll_y_max = 0;
175 if (!GetIntAttribute(WebAccessibility::ATTR_SCROLL_X, &scroll_x) ||
176 !GetIntAttribute(WebAccessibility::ATTR_SCROLL_X_MIN, &scroll_x_min) ||
177 !GetIntAttribute(WebAccessibility::ATTR_SCROLL_X_MAX, &scroll_x_max) ||
178 !GetIntAttribute(WebAccessibility::ATTR_SCROLL_Y, &scroll_y) ||
179 !GetIntAttribute(WebAccessibility::ATTR_SCROLL_Y_MIN, &scroll_y_min) ||
180 !GetIntAttribute(WebAccessibility::ATTR_SCROLL_Y_MAX, &scroll_y_max)) {
181 return;
182 }
183
184 gfx::Rect final_viewport(0, 0, location_.width(), location_.height());
185 final_viewport.Intersect(viewport);
186
187 int new_scroll_x = ComputeBestScrollOffset(
188 scroll_x,
189 subfocus.x(), subfocus.right(),
190 focus.x(), focus.right(),
191 final_viewport.x(), final_viewport.right());
192 new_scroll_x = std::max(new_scroll_x, scroll_x_min);
193 new_scroll_x = std::min(new_scroll_x, scroll_x_max);
194
195 int new_scroll_y = ComputeBestScrollOffset(
196 scroll_y,
197 subfocus.y(), subfocus.bottom(),
198 focus.y(), focus.bottom(),
199 final_viewport.y(), final_viewport.bottom());
200 new_scroll_y = std::max(new_scroll_y, scroll_y_min);
201 new_scroll_y = std::min(new_scroll_y, scroll_y_max);
202
203 manager_->ChangeScrollPosition(*this, new_scroll_x, new_scroll_y);
204 }
205
206 // static
207 int BrowserAccessibility::ComputeBestScrollOffset(
208 int current_scroll_offset,
209 int subfocus_min, int subfocus_max,
210 int focus_min, int focus_max,
211 int viewport_min, int viewport_max) {
212 int viewport_size = viewport_max - viewport_min;
213
214 // If the focus size is larger than the viewport size, shrink it in the
215 // direction of subfocus.
216 if (focus_max - focus_min > viewport_size) {
217 // Subfocus must be within focus:
218 subfocus_min = std::max(subfocus_min, focus_min);
219 subfocus_max = std::min(subfocus_max, focus_max);
220
221 // Subfocus must be no larger than the viewport size; favor top/left.
222 if (subfocus_max - subfocus_min > viewport_size)
223 subfocus_max = subfocus_min + viewport_size;
224
225 if (subfocus_min + viewport_size > focus_max) {
226 focus_min = focus_max - viewport_size;
227 } else {
228 focus_min = subfocus_min;
229 focus_max = subfocus_min + viewport_size;
230 }
231 }
232
233 // Exit now if the focus is already within the viewport.
234 if (focus_min - current_scroll_offset >= viewport_min &&
235 focus_max - current_scroll_offset <= viewport_max) {
236 return current_scroll_offset;
237 }
238
239 // Scroll left if we're too far to the right.
240 if (focus_max - current_scroll_offset > viewport_max)
241 return focus_max - viewport_max;
242
243 // Scroll right if we're too far to the left.
244 if (focus_min - current_scroll_offset < viewport_min)
245 return focus_min - viewport_min;
246
247 // This shouldn't happen.
248 NOTREACHED();
249 return current_scroll_offset;
250 }
251
166 void BrowserAccessibility::InternalAddReference() { 252 void BrowserAccessibility::InternalAddReference() {
167 ref_count_++; 253 ref_count_++;
168 } 254 }
169 255
170 void BrowserAccessibility::InternalReleaseReference(bool recursive) { 256 void BrowserAccessibility::InternalReleaseReference(bool recursive) {
171 DCHECK_GT(ref_count_, 0); 257 DCHECK_GT(ref_count_, 0);
172 258
173 if (recursive || ref_count_ == 1) { 259 if (recursive || ref_count_ == 1) {
174 for (std::vector<BrowserAccessibility*>::iterator iter = children_.begin(); 260 for (std::vector<BrowserAccessibility*>::iterator iter = children_.begin();
175 iter != children_.end(); 261 iter != children_.end();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 string16 BrowserAccessibility::GetTextRecursive() const { 351 string16 BrowserAccessibility::GetTextRecursive() const {
266 if (!name_.empty()) { 352 if (!name_.empty()) {
267 return name_; 353 return name_;
268 } 354 }
269 355
270 string16 result; 356 string16 result;
271 for (size_t i = 0; i < children_.size(); ++i) 357 for (size_t i = 0; i < children_.size(); ++i)
272 result += children_[i]->GetTextRecursive(); 358 result += children_[i]->GetTextRecursive();
273 return result; 359 return result;
274 } 360 }
OLDNEW
« no previous file with comments | « content/browser/accessibility/browser_accessibility.h ('k') | content/browser/accessibility/browser_accessibility_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698