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

Side by Side Diff: chrome/browser/views/toolbar_view.cc

Issue 272024: Allow ESC to cancel ALT+SHIFT+T in Toolbar (Closed)
Patch Set: Only allow one traversal at a time Created 11 years, 2 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 | « chrome/browser/views/toolbar_view.h ('k') | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/views/toolbar_view.h" 5 #include "chrome/browser/views/toolbar_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/drag_drop_types.h" 9 #include "app/drag_drop_types.h"
10 #include "app/gfx/canvas.h" 10 #include "app/gfx/canvas.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "chrome/common/pref_names.h" 43 #include "chrome/common/pref_names.h"
44 #include "chrome/common/pref_service.h" 44 #include "chrome/common/pref_service.h"
45 #include "grit/chromium_strings.h" 45 #include "grit/chromium_strings.h"
46 #include "grit/generated_resources.h" 46 #include "grit/generated_resources.h"
47 #include "grit/theme_resources.h" 47 #include "grit/theme_resources.h"
48 #include "net/base/net_util.h" 48 #include "net/base/net_util.h"
49 #include "views/background.h" 49 #include "views/background.h"
50 #include "views/controls/button/button_dropdown.h" 50 #include "views/controls/button/button_dropdown.h"
51 #include "views/controls/label.h" 51 #include "views/controls/label.h"
52 #include "views/drag_utils.h" 52 #include "views/drag_utils.h"
53 #include "views/focus/view_storage.h"
54 #include "views/widget/root_view.h"
53 #include "views/widget/tooltip_manager.h" 55 #include "views/widget/tooltip_manager.h"
54 #include "views/window/non_client_view.h" 56 #include "views/window/non_client_view.h"
55 #include "views/window/window.h" 57 #include "views/window/window.h"
56 58
57 static const int kControlHorizOffset = 4; 59 static const int kControlHorizOffset = 4;
58 static const int kControlVertOffset = 6; 60 static const int kControlVertOffset = 6;
59 static const int kControlIndent = 3; 61 static const int kControlIndent = 3;
60 static const int kStatusBubbleWidth = 480; 62 static const int kStatusBubbleWidth = 480;
61 63
62 // Separation between the location bar and the menus. 64 // Separation between the location bar and the menus.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 AddItemWithStringId(IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL); 146 AddItemWithStringId(IDC_ZOOM_NORMAL, IDS_ZOOM_NORMAL);
145 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS); 147 AddItemWithStringId(IDC_ZOOM_MINUS, IDS_ZOOM_MINUS);
146 } 148 }
147 149
148 //////////////////////////////////////////////////////////////////////////////// 150 ////////////////////////////////////////////////////////////////////////////////
149 // ToolbarView, public: 151 // ToolbarView, public:
150 152
151 ToolbarView::ToolbarView(Browser* browser) 153 ToolbarView::ToolbarView(Browser* browser)
152 : model_(browser->toolbar_model()), 154 : model_(browser->toolbar_model()),
153 acc_focused_view_(NULL), 155 acc_focused_view_(NULL),
156 last_focused_view_storage_id_(
157 views::ViewStorage::GetSharedInstance()->CreateStorageID()),
154 back_(NULL), 158 back_(NULL),
155 forward_(NULL), 159 forward_(NULL),
156 reload_(NULL), 160 reload_(NULL),
157 home_(NULL), 161 home_(NULL),
158 star_(NULL), 162 star_(NULL),
159 location_bar_(NULL), 163 location_bar_(NULL),
160 go_(NULL), 164 go_(NULL),
161 browser_actions_(NULL), 165 browser_actions_(NULL),
162 page_menu_(NULL), 166 page_menu_(NULL),
163 app_menu_(NULL), 167 app_menu_(NULL),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 240 }
237 // Update view_index with the available button index found. 241 // Update view_index with the available button index found.
238 view_index = current_view_index; 242 view_index = current_view_index;
239 break; 243 break;
240 } 244 }
241 // Returns the next available button index, or if no button is available in 245 // Returns the next available button index, or if no button is available in
242 // the specified direction, remains where it was. 246 // the specified direction, remains where it was.
243 return view_index; 247 return view_index;
244 } 248 }
245 249
250 void ToolbarView::InitializeTraversal() {
251 // If MSAA focus exists, we don't need to traverse, since its already active.
252 if (acc_focused_view_ != NULL)
253 return;
254
255 // Save the last focused view so that when the user presses ESC, it will
256 // return back to the last focus.
257 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
258 view_storage->StoreView(last_focused_view_storage_id_,
259 GetRootView()->GetFocusedView());
260
261 // HACK: Do not use RequestFocus() here, as the toolbar is not marked as
262 // "focusable". Instead bypass the sanity check in RequestFocus() and just
263 // force it to focus, which will do the right thing.
264 GetRootView()->FocusView(this);
265 }
266
246 //////////////////////////////////////////////////////////////////////////////// 267 ////////////////////////////////////////////////////////////////////////////////
247 // ToolbarView, Menu::BaseControllerDelegate overrides: 268 // ToolbarView, Menu::BaseControllerDelegate overrides:
248 269
249 bool ToolbarView::GetAcceleratorInfo(int id, views::Accelerator* accel) { 270 bool ToolbarView::GetAcceleratorInfo(int id, views::Accelerator* accel) {
250 return GetWidget()->GetAccelerator(id, accel); 271 return GetWidget()->GetAccelerator(id, accel);
251 } 272 }
252 273
253 //////////////////////////////////////////////////////////////////////////////// 274 ////////////////////////////////////////////////////////////////////////////////
254 // ToolbarView, views::MenuDelegate implementation: 275 // ToolbarView, views::MenuDelegate implementation:
255 276
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 // TODO(port): deal with toolbar a11y focus. 672 // TODO(port): deal with toolbar a11y focus.
652 NOTIMPLEMENTED(); 673 NOTIMPLEMENTED();
653 #endif 674 #endif
654 } 675 }
655 676
656 void ToolbarView::WillLoseFocus() { 677 void ToolbarView::WillLoseFocus() {
657 // Any tooltips that are active should be hidden when toolbar loses focus. 678 // Any tooltips that are active should be hidden when toolbar loses focus.
658 if (GetWidget() && GetWidget()->GetTooltipManager()) 679 if (GetWidget() && GetWidget()->GetTooltipManager())
659 GetWidget()->GetTooltipManager()->HideKeyboardTooltip(); 680 GetWidget()->GetTooltipManager()->HideKeyboardTooltip();
660 681
661 // Removes the Child MSAA view's focus when toolbar loses focus. 682 // Removes the Child MSAA view's focus and the view from the ViewStorage,
683 // when toolbar loses focus.
662 if (acc_focused_view_) { 684 if (acc_focused_view_) {
663 acc_focused_view_->SetHotTracked(false); 685 acc_focused_view_->SetHotTracked(false);
664 acc_focused_view_ = NULL; 686 acc_focused_view_ = NULL;
687 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
688 view_storage->RemoveView(last_focused_view_storage_id_);
665 } 689 }
666 } 690 }
667 691
668 void ToolbarView::RequestFocus() { 692 void ToolbarView::RequestFocus() {
669 // When the toolbar needs to request focus, the default implementation of 693 // When the toolbar needs to request focus, the default implementation of
670 // View::RequestFocus requires the View to be focusable. Since ToolbarView is 694 // View::RequestFocus requires the View to be focusable. Since ToolbarView is
671 // not technically focused, we need to temporarily set and remove focus so 695 // not technically focused, we need to temporarily set and remove focus so
672 // that it can focus back to its MSAA focused state. 696 // that it can focus back to its MSAA focused state. |acc_focused_view_| is
673 if (acc_focused_view_) { 697 // not necessarily set since it can be null if this view has already lost
674 SetFocusable(true); 698 // focus, such as traversing through the context menu.
675 View::RequestFocus(); 699 SetFocusable(true);
676 SetFocusable(false); 700 View::RequestFocus();
677 } else { 701 SetFocusable(false);
678 View::RequestFocus();
679 }
680 } 702 }
681 703
682 bool ToolbarView::OnKeyPressed(const views::KeyEvent& e) { 704 bool ToolbarView::OnKeyPressed(const views::KeyEvent& e) {
683 // Paranoia check, button should be initialized upon toolbar gaining focus. 705 // Paranoia check, button should be initialized upon toolbar gaining focus.
684 if (!acc_focused_view_) 706 if (!acc_focused_view_)
685 return false; 707 return false;
686 708
687 int focused_view = GetChildIndex(acc_focused_view_); 709 int focused_view = GetChildIndex(acc_focused_view_);
688 int next_view = focused_view; 710 int next_view = focused_view;
689 711
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 777
756 bool ToolbarView::OnKeyReleased(const views::KeyEvent& e) { 778 bool ToolbarView::OnKeyReleased(const views::KeyEvent& e) {
757 // Paranoia check, button should be initialized upon toolbar gaining focus. 779 // Paranoia check, button should be initialized upon toolbar gaining focus.
758 if (!acc_focused_view_) 780 if (!acc_focused_view_)
759 return false; 781 return false;
760 782
761 // Have keys be handled by the views themselves. 783 // Have keys be handled by the views themselves.
762 return acc_focused_view_->OnKeyReleased(e); 784 return acc_focused_view_->OnKeyReleased(e);
763 } 785 }
764 786
787 bool ToolbarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
788 if (acc_focused_view_ && e.GetKeyCode() == base::VKEY_ESCAPE) {
789 // Retrieve the focused view from the storage so we can request focus back
790 // to it. If |focus_view| is null, we place focus on the location bar.
791 // |acc_focused_view_| doesn't need to be resetted here since it will be
792 // dealt within the WillLoseFocus method.
793 views::ViewStorage* view_storage = views::ViewStorage::GetSharedInstance();
794 views::View* focused_view =
795 view_storage->RetrieveView(last_focused_view_storage_id_);
796 if (focused_view) {
797 view_storage->RemoveView(last_focused_view_storage_id_);
798 focused_view->RequestFocus();
799 } else {
800 location_bar_->RequestFocus();
801 }
802 return true;
803 }
804 return false;
805 }
806
765 bool ToolbarView::GetAccessibleName(std::wstring* name) { 807 bool ToolbarView::GetAccessibleName(std::wstring* name) {
766 if (!accessible_name_.empty()) { 808 if (!accessible_name_.empty()) {
767 (*name).assign(accessible_name_); 809 (*name).assign(accessible_name_);
768 return true; 810 return true;
769 } 811 }
770 return false; 812 return false;
771 } 813 }
772 814
773 bool ToolbarView::GetAccessibleRole(AccessibilityTypes::Role* role) { 815 bool ToolbarView::GetAccessibleRole(AccessibilityTypes::Role* role) {
774 DCHECK(role); 816 DCHECK(role);
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 app_menu_contents_->AddItem(IDC_ABOUT, 1198 app_menu_contents_->AddItem(IDC_ABOUT,
1157 l10n_util::GetStringFUTF16( 1199 l10n_util::GetStringFUTF16(
1158 IDS_ABOUT, 1200 IDS_ABOUT,
1159 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); 1201 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
1160 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE); 1202 app_menu_contents_->AddItemWithStringId(IDC_HELP_PAGE, IDS_HELP_PAGE);
1161 app_menu_contents_->AddSeparator(); 1203 app_menu_contents_->AddSeparator();
1162 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT); 1204 app_menu_contents_->AddItemWithStringId(IDC_EXIT, IDS_EXIT);
1163 1205
1164 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); 1206 app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get()));
1165 } 1207 }
OLDNEW
« no previous file with comments | « chrome/browser/views/toolbar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698