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

Side by Side Diff: ui/views/focus/focus_manager.cc

Issue 2696223003: [Not For Review] Handle a view that that isn't a part of Widget tree focusManager handles (Closed)
Patch Set: Created 3 years, 10 months 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
« no previous file with comments | « no previous file | no next file » | 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 #include "ui/views/focus/focus_manager.h" 5 #include "ui/views/focus/focus_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 keyboard_accessible_ = keyboard_accessible; 294 keyboard_accessible_ = keyboard_accessible;
295 // Disabling keyboard accessibility may cause the focused view to become not 295 // Disabling keyboard accessibility may cause the focused view to become not
296 // focusable. Hence advance focus if necessary. 296 // focusable. Hence advance focus if necessary.
297 AdvanceFocusIfNecessary(); 297 AdvanceFocusIfNecessary();
298 } 298 }
299 299
300 void FocusManager::SetFocusedViewWithReason( 300 void FocusManager::SetFocusedViewWithReason(
301 View* view, FocusChangeReason reason) { 301 View* view, FocusChangeReason reason) {
302 if (focused_view_ == view) 302 if (focused_view_ == view)
303 return; 303 return;
304 // TODO(oshima|achuith): This is to diagnose crbug.com/687232.
305 // Change this to DCHECK once it's resolved.
306 CHECK(!view || ContainsView(view));
307 304
308 #if !defined(OS_MACOSX) 305 #if !defined(OS_MACOSX)
309 // TODO(warx): There are some AccessiblePaneViewTest failed on macosx. 306 // TODO(warx): There are some AccessiblePaneViewTest failed on macosx.
310 // crbug.com/650859. Remove !defined(OS_MACOSX) once that is fixed. 307 // crbug.com/650859. Remove !defined(OS_MACOSX) once that is fixed.
311 // 308 //
312 // If the widget isn't active store the focused view and then attempt to 309 // If the widget isn't active store the focused view and then attempt to
313 // activate the widget. If activation succeeds |view| will be focused. 310 // activate the widget. If activation succeeds |view| will be focused.
314 // If activation fails |view| will be focused the next time the widget is 311 // If activation fails |view| will be focused the next time the widget is
315 // made active. 312 // made active.
316 if (view && !widget_->IsActive()) { 313 if (view && !widget_->IsActive()) {
317 SetStoredFocusView(view); 314 SetStoredFocusView(view);
318 widget_->Activate(); 315 widget_->Activate();
319 return; 316 return;
320 } 317 }
321 #endif 318 #endif
322 319
323 // Update the reason for the focus change (since this is checked by 320 // Update the reason for the focus change (since this is checked by
324 // some listeners), then notify all listeners. 321 // some listeners), then notify all listeners.
325 focus_change_reason_ = reason; 322 focus_change_reason_ = reason;
326 for (FocusChangeListener& observer : focus_change_listeners_) 323 for (FocusChangeListener& observer : focus_change_listeners_)
327 observer.OnWillChangeFocus(focused_view_, view); 324 observer.OnWillChangeFocus(focused_view_, view);
328 325
329 View* old_focused_view = focused_view_; 326 View* old_focused_view = focused_view_;
330 focused_view_ = view; 327
328 bool focused_view_on_other_widget = view && !ContainsView(view);
329 if (focused_view_on_other_widget) {
330 focused_view_ = nullptr;
331 } else {
332 focused_view_ = view;
333 }
331 if (old_focused_view) 334 if (old_focused_view)
332 old_focused_view->Blur(); 335 old_focused_view->Blur();
333 // Also make |focused_view_| the stored focus view. This way the stored focus 336 // Also make |focused_view_| the stored focus view. This way the stored focus
334 // view is remembered if focus changes are requested prior to a show or while 337 // view is remembered if focus changes are requested prior to a show or while
335 // hidden. 338 // hidden.
336 SetStoredFocusView(focused_view_); 339 if (!focused_view_on_other_widget) {
337 if (focused_view_) 340 SetStoredFocusView(focused_view_);
341 }
342 if (focused_view_) {
338 focused_view_->Focus(); 343 focused_view_->Focus();
344 } else if (view) {
345 view->RequestFocus();
346 }
339 347
340 for (FocusChangeListener& observer : focus_change_listeners_) 348 for (FocusChangeListener& observer : focus_change_listeners_)
341 observer.OnDidChangeFocus(old_focused_view, focused_view_); 349 observer.OnDidChangeFocus(old_focused_view, focused_view_);
342 } 350 }
343 351
344 void FocusManager::ClearFocus() { 352 void FocusManager::ClearFocus() {
345 // SetFocusedView(NULL) is going to clear out the stored view to. We need to 353 // SetFocusedView(NULL) is going to clear out the stored view to. We need to
346 // persist it in this case. 354 // persist it in this case.
347 views::View* focused_view = GetStoredFocusView(); 355 views::View* focused_view = GetStoredFocusView();
348 SetFocusedView(NULL); 356 SetFocusedView(NULL);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // |keyboard_accessible_| is only used on Mac. 567 // |keyboard_accessible_| is only used on Mac.
560 #if defined(OS_MACOSX) 568 #if defined(OS_MACOSX)
561 return keyboard_accessible_ ? view->IsAccessibilityFocusable() 569 return keyboard_accessible_ ? view->IsAccessibilityFocusable()
562 : view->IsFocusable(); 570 : view->IsFocusable();
563 #else 571 #else
564 return view->IsAccessibilityFocusable(); 572 return view->IsAccessibilityFocusable();
565 #endif 573 #endif
566 } 574 }
567 575
568 } // namespace views 576 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698