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

Side by Side Diff: ui/views/view.cc

Issue 108063004: Give up focus if the focused view becomes unfocusable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try to advance focus first Created 7 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) 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 446 }
447 447
448 void View::SetVisible(bool visible) { 448 void View::SetVisible(bool visible) {
449 if (visible != visible_) { 449 if (visible != visible_) {
450 // If the View is currently visible, schedule paint to refresh parent. 450 // If the View is currently visible, schedule paint to refresh parent.
451 // TODO(beng): not sure we should be doing this if we have a layer. 451 // TODO(beng): not sure we should be doing this if we have a layer.
452 if (visible_) 452 if (visible_)
453 SchedulePaint(); 453 SchedulePaint();
454 454
455 visible_ = visible; 455 visible_ = visible;
456 ReviseFocusedView();
456 457
457 // Notify the parent. 458 // Notify the parent.
458 if (parent_) 459 if (parent_)
459 parent_->ChildVisibilityChanged(this); 460 parent_->ChildVisibilityChanged(this);
460 461
461 // This notifies all sub-views recursively. 462 // This notifies all sub-views recursively.
462 PropagateVisibilityNotifications(this, visible_); 463 PropagateVisibilityNotifications(this, visible_);
463 UpdateLayerVisibility(); 464 UpdateLayerVisibility();
464 465
465 // If we are newly visible, schedule paint. 466 // If we are newly visible, schedule paint.
466 if (visible_) 467 if (visible_)
467 SchedulePaint(); 468 SchedulePaint();
468 } 469 }
469 } 470 }
470 471
471 bool View::IsDrawn() const { 472 bool View::IsDrawn() const {
472 return visible_ && parent_ ? parent_->IsDrawn() : false; 473 return visible_ && parent_ ? parent_->IsDrawn() : false;
473 } 474 }
474 475
475 void View::SetEnabled(bool enabled) { 476 void View::SetEnabled(bool enabled) {
476 if (enabled != enabled_) { 477 if (enabled != enabled_) {
477 enabled_ = enabled; 478 enabled_ = enabled;
479 ReviseFocusedView();
478 OnEnabledChanged(); 480 OnEnabledChanged();
479 } 481 }
480 } 482 }
481 483
482 void View::OnEnabledChanged() { 484 void View::OnEnabledChanged() {
483 SchedulePaint(); 485 SchedulePaint();
484 } 486 }
485 487
486 // Transformations ------------------------------------------------------------- 488 // Transformations -------------------------------------------------------------
487 489
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 View* View::GetPreviousFocusableView() { 1200 View* View::GetPreviousFocusableView() {
1199 return previous_focusable_view_; 1201 return previous_focusable_view_;
1200 } 1202 }
1201 1203
1202 void View::SetNextFocusableView(View* view) { 1204 void View::SetNextFocusableView(View* view) {
1203 if (view) 1205 if (view)
1204 view->previous_focusable_view_ = this; 1206 view->previous_focusable_view_ = this;
1205 next_focusable_view_ = view; 1207 next_focusable_view_ = view;
1206 } 1208 }
1207 1209
1210 void View::SetFocusable(bool focusable) {
1211 if (focusable_ == focusable)
1212 return;
1213
1214 focusable_ = focusable;
1215 ReviseFocusedView();
1216 }
1217
1208 bool View::IsFocusable() const { 1218 bool View::IsFocusable() const {
1209 return focusable_ && enabled_ && IsDrawn(); 1219 return focusable_ && enabled_ && IsDrawn();
1210 } 1220 }
1211 1221
1212 bool View::IsAccessibilityFocusable() const { 1222 bool View::IsAccessibilityFocusable() const {
1213 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn(); 1223 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn();
1214 } 1224 }
1215 1225
1226 void View::SetAccessibilityFocusable(bool accessibility_focusable) {
1227 if (accessibility_focusable_ == accessibility_focusable)
1228 return;
1229
1230 accessibility_focusable_ = accessibility_focusable;
1231 ReviseFocusedView();
1232 }
1233
1216 FocusManager* View::GetFocusManager() { 1234 FocusManager* View::GetFocusManager() {
1217 Widget* widget = GetWidget(); 1235 Widget* widget = GetWidget();
1218 return widget ? widget->GetFocusManager() : NULL; 1236 return widget ? widget->GetFocusManager() : NULL;
1219 } 1237 }
1220 1238
1221 const FocusManager* View::GetFocusManager() const { 1239 const FocusManager* View::GetFocusManager() const {
1222 const Widget* widget = GetWidget(); 1240 const Widget* widget = GetWidget();
1223 return widget ? widget->GetFocusManager() : NULL; 1241 return widget ? widget->GetFocusManager() : NULL;
1224 } 1242 }
1225 1243
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2329 View* prev = children_[index]->GetPreviousFocusableView(); 2347 View* prev = children_[index]->GetPreviousFocusableView();
2330 v->previous_focusable_view_ = prev; 2348 v->previous_focusable_view_ = prev;
2331 v->next_focusable_view_ = children_[index]; 2349 v->next_focusable_view_ = children_[index];
2332 if (prev) 2350 if (prev)
2333 prev->next_focusable_view_ = v; 2351 prev->next_focusable_view_ = v;
2334 children_[index]->previous_focusable_view_ = v; 2352 children_[index]->previous_focusable_view_ = v;
2335 } 2353 }
2336 } 2354 }
2337 } 2355 }
2338 2356
2357 void View::ReviseFocusedView() {
2358 FocusManager* focus_manager = GetFocusManager();
2359 if (focus_manager)
2360 focus_manager->ReviseFocusedView();
2361 }
2362
2339 // System events --------------------------------------------------------------- 2363 // System events ---------------------------------------------------------------
2340 2364
2341 void View::PropagateThemeChanged() { 2365 void View::PropagateThemeChanged() {
2342 for (int i = child_count() - 1; i >= 0; --i) 2366 for (int i = child_count() - 1; i >= 0; --i)
2343 child_at(i)->PropagateThemeChanged(); 2367 child_at(i)->PropagateThemeChanged();
2344 OnThemeChanged(); 2368 OnThemeChanged();
2345 } 2369 }
2346 2370
2347 void View::PropagateLocaleChanged() { 2371 void View::PropagateLocaleChanged() {
2348 for (int i = child_count() - 1; i >= 0; --i) 2372 for (int i = child_count() - 1; i >= 0; --i)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2386 // Message the RootView to do the drag and drop. That way if we're removed 2410 // Message the RootView to do the drag and drop. That way if we're removed
2387 // the RootView can detect it and avoid calling us back. 2411 // the RootView can detect it and avoid calling us back.
2388 gfx::Point widget_location(event.location()); 2412 gfx::Point widget_location(event.location());
2389 ConvertPointToWidget(this, &widget_location); 2413 ConvertPointToWidget(this, &widget_location);
2390 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2414 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2391 // WARNING: we may have been deleted. 2415 // WARNING: we may have been deleted.
2392 return true; 2416 return true;
2393 } 2417 }
2394 2418
2395 } // namespace views 2419 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | ui/views/view_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698