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

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: Rebased 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
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 456
457 if (!visible) {
sky 2013/12/07 00:29:13 You have this code in a bunch of places. I think w
mohsen 2013/12/11 20:10:12 I have extracted the common code and moved it to t
458 // If the View has focus or contains the focused view, clear focus.
459 FocusManager* focus_manager = GetFocusManager();
460 if (focus_manager && Contains(focus_manager->GetFocusedView()))
461 focus_manager->ClearFocus();
462 }
463
457 // Notify the parent. 464 // Notify the parent.
458 if (parent_) 465 if (parent_)
459 parent_->ChildVisibilityChanged(this); 466 parent_->ChildVisibilityChanged(this);
460 467
461 // This notifies all sub-views recursively. 468 // This notifies all sub-views recursively.
462 PropagateVisibilityNotifications(this, visible_); 469 PropagateVisibilityNotifications(this, visible_);
463 UpdateLayerVisibility(); 470 UpdateLayerVisibility();
464 471
465 // If we are newly visible, schedule paint. 472 // If we are newly visible, schedule paint.
466 if (visible_) 473 if (visible_)
467 SchedulePaint(); 474 SchedulePaint();
468 } 475 }
469 } 476 }
470 477
471 bool View::IsDrawn() const { 478 bool View::IsDrawn() const {
472 return visible_ && parent_ ? parent_->IsDrawn() : false; 479 return visible_ && parent_ ? parent_->IsDrawn() : false;
473 } 480 }
474 481
475 void View::SetEnabled(bool enabled) { 482 void View::SetEnabled(bool enabled) {
476 if (enabled != enabled_) { 483 if (enabled != enabled_) {
477 enabled_ = enabled; 484 enabled_ = enabled;
485 if (!enabled) {
486 // If the View has focus, clear focus.
487 FocusManager* focus_manager = GetFocusManager();
488 if (focus_manager && focus_manager->GetFocusedView() == this)
489 focus_manager->ClearFocus();
490 }
478 OnEnabledChanged(); 491 OnEnabledChanged();
479 } 492 }
480 } 493 }
481 494
482 void View::OnEnabledChanged() { 495 void View::OnEnabledChanged() {
483 SchedulePaint(); 496 SchedulePaint();
484 } 497 }
485 498
486 // Transformations ------------------------------------------------------------- 499 // Transformations -------------------------------------------------------------
487 500
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 View* View::GetPreviousFocusableView() { 1211 View* View::GetPreviousFocusableView() {
1199 return previous_focusable_view_; 1212 return previous_focusable_view_;
1200 } 1213 }
1201 1214
1202 void View::SetNextFocusableView(View* view) { 1215 void View::SetNextFocusableView(View* view) {
1203 if (view) 1216 if (view)
1204 view->previous_focusable_view_ = this; 1217 view->previous_focusable_view_ = this;
1205 next_focusable_view_ = view; 1218 next_focusable_view_ = view;
1206 } 1219 }
1207 1220
1221 void View::SetFocusable(bool focusable) {
1222 focusable_ = focusable;
1223 if (!focusable && !IsAccessibilityFocusable()) {
1224 // If the View has focus, clear focus.
1225 FocusManager* focus_manager = GetFocusManager();
1226 if (focus_manager && focus_manager->GetFocusedView() == this)
1227 focus_manager->ClearFocus();
1228 }
1229 }
1230
1208 bool View::IsFocusable() const { 1231 bool View::IsFocusable() const {
1209 return focusable_ && enabled_ && IsDrawn(); 1232 return focusable_ && enabled_ && IsDrawn();
1210 } 1233 }
1211 1234
1212 bool View::IsAccessibilityFocusable() const { 1235 bool View::IsAccessibilityFocusable() const {
1213 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn(); 1236 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn();
1214 } 1237 }
1215 1238
1239 void View::SetAccessibilityFocusable(bool accessibility_focusable) {
1240 accessibility_focusable_ = accessibility_focusable;
1241 if (!accessibility_focusable && !IsFocusable()) {
1242 // If the View has focus, clear focus.
1243 FocusManager* focus_manager = GetFocusManager();
1244 if (focus_manager && focus_manager->GetFocusedView() == this)
1245 focus_manager->ClearFocus();
1246 }
1247 }
1248
1216 FocusManager* View::GetFocusManager() { 1249 FocusManager* View::GetFocusManager() {
1217 Widget* widget = GetWidget(); 1250 Widget* widget = GetWidget();
1218 return widget ? widget->GetFocusManager() : NULL; 1251 return widget ? widget->GetFocusManager() : NULL;
1219 } 1252 }
1220 1253
1221 const FocusManager* View::GetFocusManager() const { 1254 const FocusManager* View::GetFocusManager() const {
1222 const Widget* widget = GetWidget(); 1255 const Widget* widget = GetWidget();
1223 return widget ? widget->GetFocusManager() : NULL; 1256 return widget ? widget->GetFocusManager() : NULL;
1224 } 1257 }
1225 1258
(...skipping 1160 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 2419 // 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. 2420 // the RootView can detect it and avoid calling us back.
2388 gfx::Point widget_location(event.location()); 2421 gfx::Point widget_location(event.location());
2389 ConvertPointToWidget(this, &widget_location); 2422 ConvertPointToWidget(this, &widget_location);
2390 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2423 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2391 // WARNING: we may have been deleted. 2424 // WARNING: we may have been deleted.
2392 return true; 2425 return true;
2393 } 2426 }
2394 2427
2395 } // namespace views 2428 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698