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

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: Extracted to common code into FocusManager class 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 ClearFocusIfUnfocusable();
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 ClearFocusIfUnfocusable();
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 focusable_ = focusable;
sky 2013/12/11 21:29:29 early out if didn't change.
mohsen 2013/12/12 18:26:54 Done.
1212 ClearFocusIfUnfocusable();
1213 }
1214
1208 bool View::IsFocusable() const { 1215 bool View::IsFocusable() const {
1209 return focusable_ && enabled_ && IsDrawn(); 1216 return focusable_ && enabled_ && IsDrawn();
1210 } 1217 }
1211 1218
1212 bool View::IsAccessibilityFocusable() const { 1219 bool View::IsAccessibilityFocusable() const {
1213 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn(); 1220 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn();
1214 } 1221 }
1215 1222
1223 void View::SetAccessibilityFocusable(bool accessibility_focusable) {
1224 accessibility_focusable_ = accessibility_focusable;
sky 2013/12/11 21:29:29 early out if didn't change.
mohsen 2013/12/12 18:26:54 Done.
1225 ClearFocusIfUnfocusable();
1226 }
1227
1216 FocusManager* View::GetFocusManager() { 1228 FocusManager* View::GetFocusManager() {
1217 Widget* widget = GetWidget(); 1229 Widget* widget = GetWidget();
1218 return widget ? widget->GetFocusManager() : NULL; 1230 return widget ? widget->GetFocusManager() : NULL;
1219 } 1231 }
1220 1232
1221 const FocusManager* View::GetFocusManager() const { 1233 const FocusManager* View::GetFocusManager() const {
1222 const Widget* widget = GetWidget(); 1234 const Widget* widget = GetWidget();
1223 return widget ? widget->GetFocusManager() : NULL; 1235 return widget ? widget->GetFocusManager() : NULL;
1224 } 1236 }
1225 1237
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2329 View* prev = children_[index]->GetPreviousFocusableView(); 2341 View* prev = children_[index]->GetPreviousFocusableView();
2330 v->previous_focusable_view_ = prev; 2342 v->previous_focusable_view_ = prev;
2331 v->next_focusable_view_ = children_[index]; 2343 v->next_focusable_view_ = children_[index];
2332 if (prev) 2344 if (prev)
2333 prev->next_focusable_view_ = v; 2345 prev->next_focusable_view_ = v;
2334 children_[index]->previous_focusable_view_ = v; 2346 children_[index]->previous_focusable_view_ = v;
2335 } 2347 }
2336 } 2348 }
2337 } 2349 }
2338 2350
2351 void View::ClearFocusIfUnfocusable() {
2352 FocusManager* focus_manager = GetFocusManager();
2353 if (focus_manager)
2354 focus_manager->ClearFocusIfUnfocusable();
2355 }
2356
2339 // System events --------------------------------------------------------------- 2357 // System events ---------------------------------------------------------------
2340 2358
2341 void View::PropagateThemeChanged() { 2359 void View::PropagateThemeChanged() {
2342 for (int i = child_count() - 1; i >= 0; --i) 2360 for (int i = child_count() - 1; i >= 0; --i)
2343 child_at(i)->PropagateThemeChanged(); 2361 child_at(i)->PropagateThemeChanged();
2344 OnThemeChanged(); 2362 OnThemeChanged();
2345 } 2363 }
2346 2364
2347 void View::PropagateLocaleChanged() { 2365 void View::PropagateLocaleChanged() {
2348 for (int i = child_count() - 1; i >= 0; --i) 2366 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 2404 // 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. 2405 // the RootView can detect it and avoid calling us back.
2388 gfx::Point widget_location(event.location()); 2406 gfx::Point widget_location(event.location());
2389 ConvertPointToWidget(this, &widget_location); 2407 ConvertPointToWidget(this, &widget_location);
2390 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2408 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2391 // WARNING: we may have been deleted. 2409 // WARNING: we may have been deleted.
2392 return true; 2410 return true;
2393 } 2411 }
2394 2412
2395 } // namespace views 2413 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698