OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
6 | 6 |
7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 399 } |
400 | 400 |
401 void View::SetVisible(bool visible) { | 401 void View::SetVisible(bool visible) { |
402 if (visible != visible_) { | 402 if (visible != visible_) { |
403 // If the View is currently visible, schedule paint to refresh parent. | 403 // If the View is currently visible, schedule paint to refresh parent. |
404 // TODO(beng): not sure we should be doing this if we have a layer. | 404 // TODO(beng): not sure we should be doing this if we have a layer. |
405 if (visible_) | 405 if (visible_) |
406 SchedulePaint(); | 406 SchedulePaint(); |
407 | 407 |
408 visible_ = visible; | 408 visible_ = visible; |
| 409 AdvanceFocusIfNecessary(); |
409 | 410 |
410 // Notify the parent. | 411 // Notify the parent. |
411 if (parent_) | 412 if (parent_) |
412 parent_->ChildVisibilityChanged(this); | 413 parent_->ChildVisibilityChanged(this); |
413 | 414 |
414 // This notifies all sub-views recursively. | 415 // This notifies all sub-views recursively. |
415 PropagateVisibilityNotifications(this, visible_); | 416 PropagateVisibilityNotifications(this, visible_); |
416 UpdateLayerVisibility(); | 417 UpdateLayerVisibility(); |
417 | 418 |
418 // If we are newly visible, schedule paint. | 419 // If we are newly visible, schedule paint. |
419 if (visible_) | 420 if (visible_) |
420 SchedulePaint(); | 421 SchedulePaint(); |
421 } | 422 } |
422 } | 423 } |
423 | 424 |
424 bool View::IsDrawn() const { | 425 bool View::IsDrawn() const { |
425 return visible_ && parent_ ? parent_->IsDrawn() : false; | 426 return visible_ && parent_ ? parent_->IsDrawn() : false; |
426 } | 427 } |
427 | 428 |
428 void View::SetEnabled(bool enabled) { | 429 void View::SetEnabled(bool enabled) { |
429 if (enabled != enabled_) { | 430 if (enabled != enabled_) { |
430 enabled_ = enabled; | 431 enabled_ = enabled; |
| 432 AdvanceFocusIfNecessary(); |
431 OnEnabledChanged(); | 433 OnEnabledChanged(); |
432 } | 434 } |
433 } | 435 } |
434 | 436 |
435 void View::OnEnabledChanged() { | 437 void View::OnEnabledChanged() { |
436 SchedulePaint(); | 438 SchedulePaint(); |
437 } | 439 } |
438 | 440 |
439 // Transformations ------------------------------------------------------------- | 441 // Transformations ------------------------------------------------------------- |
440 | 442 |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 if (view) | 1139 if (view) |
1138 view->previous_focusable_view_ = this; | 1140 view->previous_focusable_view_ = this; |
1139 next_focusable_view_ = view; | 1141 next_focusable_view_ = view; |
1140 } | 1142 } |
1141 | 1143 |
1142 void View::SetFocusable(bool focusable) { | 1144 void View::SetFocusable(bool focusable) { |
1143 if (focusable_ == focusable) | 1145 if (focusable_ == focusable) |
1144 return; | 1146 return; |
1145 | 1147 |
1146 focusable_ = focusable; | 1148 focusable_ = focusable; |
| 1149 AdvanceFocusIfNecessary(); |
1147 } | 1150 } |
1148 | 1151 |
1149 bool View::IsFocusable() const { | 1152 bool View::IsFocusable() const { |
1150 return focusable_ && enabled_ && IsDrawn(); | 1153 return focusable_ && enabled_ && IsDrawn(); |
1151 } | 1154 } |
1152 | 1155 |
1153 bool View::IsAccessibilityFocusable() const { | 1156 bool View::IsAccessibilityFocusable() const { |
1154 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn(); | 1157 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn(); |
1155 } | 1158 } |
1156 | 1159 |
1157 void View::SetAccessibilityFocusable(bool accessibility_focusable) { | 1160 void View::SetAccessibilityFocusable(bool accessibility_focusable) { |
1158 if (accessibility_focusable_ == accessibility_focusable) | 1161 if (accessibility_focusable_ == accessibility_focusable) |
1159 return; | 1162 return; |
1160 | 1163 |
1161 accessibility_focusable_ = accessibility_focusable; | 1164 accessibility_focusable_ = accessibility_focusable; |
| 1165 AdvanceFocusIfNecessary(); |
1162 } | 1166 } |
1163 | 1167 |
1164 FocusManager* View::GetFocusManager() { | 1168 FocusManager* View::GetFocusManager() { |
1165 Widget* widget = GetWidget(); | 1169 Widget* widget = GetWidget(); |
1166 return widget ? widget->GetFocusManager() : NULL; | 1170 return widget ? widget->GetFocusManager() : NULL; |
1167 } | 1171 } |
1168 | 1172 |
1169 const FocusManager* View::GetFocusManager() const { | 1173 const FocusManager* View::GetFocusManager() const { |
1170 const Widget* widget = GetWidget(); | 1174 const Widget* widget = GetWidget(); |
1171 return widget ? widget->GetFocusManager() : NULL; | 1175 return widget ? widget->GetFocusManager() : NULL; |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2364 View* prev = children_[index]->GetPreviousFocusableView(); | 2368 View* prev = children_[index]->GetPreviousFocusableView(); |
2365 v->previous_focusable_view_ = prev; | 2369 v->previous_focusable_view_ = prev; |
2366 v->next_focusable_view_ = children_[index]; | 2370 v->next_focusable_view_ = children_[index]; |
2367 if (prev) | 2371 if (prev) |
2368 prev->next_focusable_view_ = v; | 2372 prev->next_focusable_view_ = v; |
2369 children_[index]->previous_focusable_view_ = v; | 2373 children_[index]->previous_focusable_view_ = v; |
2370 } | 2374 } |
2371 } | 2375 } |
2372 } | 2376 } |
2373 | 2377 |
| 2378 void View::AdvanceFocusIfNecessary() { |
| 2379 // Focus should only be advanced if this is the focused view and has become |
| 2380 // unfocusable. If it is still focusable, we can return early avoiding furthur |
| 2381 // unnecessary checks. |
| 2382 if (IsAccessibilityFocusable()) |
| 2383 return; |
| 2384 |
| 2385 FocusManager* focus_manager = GetFocusManager(); |
| 2386 if (focus_manager) |
| 2387 focus_manager->AdvanceFocusIfNecessary(); |
| 2388 } |
| 2389 |
2374 // System events --------------------------------------------------------------- | 2390 // System events --------------------------------------------------------------- |
2375 | 2391 |
2376 void View::PropagateThemeChanged() { | 2392 void View::PropagateThemeChanged() { |
2377 for (int i = child_count() - 1; i >= 0; --i) | 2393 for (int i = child_count() - 1; i >= 0; --i) |
2378 child_at(i)->PropagateThemeChanged(); | 2394 child_at(i)->PropagateThemeChanged(); |
2379 OnThemeChanged(); | 2395 OnThemeChanged(); |
2380 } | 2396 } |
2381 | 2397 |
2382 void View::PropagateLocaleChanged() { | 2398 void View::PropagateLocaleChanged() { |
2383 for (int i = child_count() - 1; i >= 0; --i) | 2399 for (int i = child_count() - 1; i >= 0; --i) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 // Message the RootView to do the drag and drop. That way if we're removed | 2437 // Message the RootView to do the drag and drop. That way if we're removed |
2422 // the RootView can detect it and avoid calling us back. | 2438 // the RootView can detect it and avoid calling us back. |
2423 gfx::Point widget_location(event.location()); | 2439 gfx::Point widget_location(event.location()); |
2424 ConvertPointToWidget(this, &widget_location); | 2440 ConvertPointToWidget(this, &widget_location); |
2425 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2441 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2426 // WARNING: we may have been deleted. | 2442 // WARNING: we may have been deleted. |
2427 return true; | 2443 return true; |
2428 } | 2444 } |
2429 | 2445 |
2430 } // namespace views | 2446 } // namespace views |
OLD | NEW |