diff options
author | alicet@chromium.org <alicet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 19:59:52 +0000 |
---|---|---|
committer | alicet@chromium.org <alicet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-10 19:59:52 +0000 |
commit | 2a7f5ae1c146e8e726a15d2422eb7d6022daefed (patch) | |
tree | 0aa3fc6c128caf7553308aeb03a3cb63d9fa569b | |
parent | 2fb4e7cd82637c40a4f99b95340c7ddaf85a5309 (diff) | |
download | chromium_src-2a7f5ae1c146e8e726a15d2422eb7d6022daefed.zip chromium_src-2a7f5ae1c146e8e726a15d2422eb7d6022daefed.tar.gz chromium_src-2a7f5ae1c146e8e726a15d2422eb7d6022daefed.tar.bz2 |
Add DidChangeFocus to FocusChangeListener.
Rename FocusChangeListener interface to OnWillChangeFocus and OnDidChangeFocus
Move location bar focus interaction from AccessibilityPaneView to ToolBarView.
BUG=101940
TEST=None
Review URL: http://codereview.chromium.org/8416058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109482 0039d316-1c4b-4281-b951-d872f2087c98
49 files changed, 438 insertions, 319 deletions
diff --git a/chrome/browser/automation/testing_automation_provider_views.cc b/chrome/browser/automation/testing_automation_provider_views.cc index fd40884..8abbf35 100644 --- a/chrome/browser/automation/testing_automation_provider_views.cc +++ b/chrome/browser/automation/testing_automation_provider_views.cc @@ -36,7 +36,7 @@ class ViewFocusChangeWaiter : public views::FocusChangeListener { focus_manager_->AddFocusChangeListener(this); // Call the focus change notification once in case the focus has // already changed. - FocusWillChange(NULL, focus_manager_->GetFocusedView()); + OnWillChangeFocus(NULL, focus_manager_->GetFocusedView()); } virtual ~ViewFocusChangeWaiter() { @@ -44,19 +44,12 @@ class ViewFocusChangeWaiter : public views::FocusChangeListener { } // Inherited from FocusChangeListener - virtual void FocusWillChange(views::View* focused_before, - views::View* focused_now) { - // This listener is called before focus actually changes. Post a task - // that will get run after focus changes. - MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&ViewFocusChangeWaiter::FocusChanged, - weak_factory_.GetWeakPtr(), focused_before, focused_now)); + virtual void OnWillChangeFocus(views::View* focused_before, + views::View* focused_now) { } - private: - void FocusChanged(views::View* focused_before, - views::View* focused_now) { + virtual void OnDidChangeFocus(views::View* focused_before, + views::View* focused_now) { if (focused_now && focused_now->id() != previous_view_id_) { AutomationMsg_WaitForFocusedViewIDToChange::WriteReplyParams( reply_message_, true, focused_now->id()); @@ -66,6 +59,7 @@ class ViewFocusChangeWaiter : public views::FocusChangeListener { } } + private: views::FocusManager* focus_manager_; int previous_view_id_; AutomationProvider* automation_; diff --git a/chrome/browser/chromeos/frame/browser_view.cc b/chrome/browser/chromeos/frame/browser_view.cc index 3c75903..8605e91 100644 --- a/chrome/browser/chromeos/frame/browser_view.cc +++ b/chrome/browser/chromeos/frame/browser_view.cc @@ -388,8 +388,7 @@ void BrowserView::ShowInternal(bool is_active) { } void BrowserView::FocusChromeOSStatus() { - SaveFocusedView(); - status_area_->SetPaneFocus(last_focused_view_storage_id(), NULL); + status_area_->SetPaneFocus(NULL); } views::LayoutManager* BrowserView::CreateLayoutManager() const { @@ -574,7 +573,7 @@ void BrowserView::DidProcessEvent(GdkEvent* event) { // BrowserView protected: void BrowserView::GetAccessiblePanes( - std::vector<AccessiblePaneView*>* panes) { + std::vector<views::AccessiblePaneView*>* panes) { ::BrowserView::GetAccessiblePanes(panes); panes->push_back(status_area_); } diff --git a/chrome/browser/chromeos/frame/browser_view.h b/chrome/browser/chromeos/frame/browser_view.h index d09e411..21a0aef 100644 --- a/chrome/browser/chromeos/frame/browser_view.h +++ b/chrome/browser/chromeos/frame/browser_view.h @@ -26,6 +26,7 @@ class SimpleMenuModel; } // namespace ui namespace views { +class AccessiblePaneView; class ImageButton; class ImageView; class MenuDelegate; @@ -120,7 +121,7 @@ class BrowserView : public ::BrowserView, protected: virtual void GetAccessiblePanes( - std::vector<AccessiblePaneView*>* panes); + std::vector<views::AccessiblePaneView*>* panes); private: void InitSystemMenu(); diff --git a/chrome/browser/chromeos/status/status_area_view.cc b/chrome/browser/chromeos/status/status_area_view.cc index 24b0d16..3210d82 100644 --- a/chrome/browser/chromeos/status/status_area_view.cc +++ b/chrome/browser/chromeos/status/status_area_view.cc @@ -139,12 +139,9 @@ void StatusAreaView::ReturnFocus(bool reverse) { return_focus_cb_.Run(reverse); } -void StatusAreaView::FocusWillChange(views::View* focused_before, - views::View* focused_now) { - // Call superclass. - AccessiblePaneView::FocusWillChange(focused_before, focused_now); - - // If focus has been wrapped, postpone focus return task. +void StatusAreaView::OnDidChangeFocus(views::View* focused_before, + views::View* focused_now) { + views::AccessiblePaneView::OnDidChangeFocus(focused_before, focused_now); if (need_return_focus_) { const views::View* first = GetFirstFocusableChild(); const views::View* last = GetLastFocusableChild(); @@ -152,7 +149,6 @@ void StatusAreaView::FocusWillChange(views::View* focused_before, const bool last_to_first = (focused_now == first && focused_before == last); if (first_to_last || last_to_first) - MessageLoop::current()->PostTask(FROM_HERE, - base::Bind(&StatusAreaView::ReturnFocus, AsWeakPtr(), first_to_last)); + ReturnFocus(first_to_last); } } diff --git a/chrome/browser/chromeos/status/status_area_view.h b/chrome/browser/chromeos/status/status_area_view.h index f2da1ee..b7da1f2 100644 --- a/chrome/browser/chromeos/status/status_area_view.h +++ b/chrome/browser/chromeos/status/status_area_view.h @@ -11,12 +11,12 @@ #include "base/basictypes.h" #include "base/callback.h" #include "chrome/browser/chromeos/status/status_area_button.h" -#include "chrome/browser/ui/views/accessible_pane_view.h" +#include "views/accessible_pane_view.h" #include "views/view.h" // This class is used to wrap the small informative widgets in the upper-right // of the window title bar. It is used on ChromeOS only. -class StatusAreaView : public AccessiblePaneView, +class StatusAreaView : public views::AccessiblePaneView, public base::SupportsWeakPtr<StatusAreaView> { public: explicit StatusAreaView(); @@ -36,8 +36,8 @@ class StatusAreaView : public AccessiblePaneView, const ReturnFocusCallback& return_focus_cb); // Overridden from views::FocusChangeListener: - virtual void FocusWillChange(views::View* focused_before, - views::View* focused_now) OVERRIDE; + virtual void OnDidChangeFocus(views::View* focused_before, + views::View* focused_now) OVERRIDE; // views::View* overrides. virtual gfx::Size GetPreferredSize() OVERRIDE; diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index af3e5db..4d6e79a 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -186,7 +186,7 @@ void ExtensionBrowserEventRouter::OnBrowserRemoved(const Browser* browser) { } #if defined(TOOLKIT_VIEWS) -void ExtensionBrowserEventRouter::NativeFocusWillChange( +void ExtensionBrowserEventRouter::OnNativeFocusChange( gfx::NativeView focused_before, gfx::NativeView focused_now) { if (!focused_now) diff --git a/chrome/browser/extensions/extension_browser_event_router.h b/chrome/browser/extensions/extension_browser_event_router.h index d0fbf3e..12417f9 100644 --- a/chrome/browser/extensions/extension_browser_event_router.h +++ b/chrome/browser/extensions/extension_browser_event_router.h @@ -47,8 +47,8 @@ class ExtensionBrowserEventRouter : public TabStripModelObserver, virtual void OnBrowserSetLastActive(const Browser* browser) OVERRIDE; #if defined(TOOLKIT_VIEWS) - virtual void NativeFocusWillChange(gfx::NativeView focused_before, - gfx::NativeView focused_now) OVERRIDE; + virtual void OnNativeFocusChange(gfx::NativeView focused_before, + gfx::NativeView focused_now) OVERRIDE; #elif defined(TOOLKIT_GTK) virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; #endif diff --git a/chrome/browser/ui/views/detachable_toolbar_view.h b/chrome/browser/ui/views/detachable_toolbar_view.h index 67fddcd..1bd363f 100644 --- a/chrome/browser/ui/views/detachable_toolbar_view.h +++ b/chrome/browser/ui/views/detachable_toolbar_view.h @@ -6,14 +6,14 @@ #define CHROME_BROWSER_UI_VIEWS_DETACHABLE_TOOLBAR_VIEW_H_ #pragma once -#include "chrome/browser/ui/views/accessible_pane_view.h" +#include "views/accessible_pane_view.h" class SkBitmap; struct SkRect; // DetachableToolbarView contains functionality common to views that can detach // from the Chrome frame, such as the BookmarkBarView and the Extension shelf. -class DetachableToolbarView : public AccessiblePaneView { +class DetachableToolbarView : public views::AccessiblePaneView { public: // The color gradient start value close to the edge of the divider. static const SkColor kEdgeDividerColor; diff --git a/chrome/browser/ui/views/download/download_shelf_view.cc b/chrome/browser/ui/views/download/download_shelf_view.cc index 2592e64..70c335b 100644 --- a/chrome/browser/ui/views/download/download_shelf_view.cc +++ b/chrome/browser/ui/views/download/download_shelf_view.cc @@ -127,11 +127,15 @@ void DownloadShelfView::MouseMovedOutOfView() { Close(); } -void DownloadShelfView::FocusWillChange(views::View* focused_before, - views::View* focused_now) { +void DownloadShelfView::OnWillChangeFocus(views::View* focused_before, + views::View* focused_now) { SchedulePaintForDownloadItem(focused_before); SchedulePaintForDownloadItem(focused_now); - AccessiblePaneView::FocusWillChange(focused_before, focused_now); +} + +void DownloadShelfView::OnDidChangeFocus(views::View* focused_before, + views::View* focused_now) { + AccessiblePaneView::OnDidChangeFocus(focused_before, focused_now); } void DownloadShelfView::RemoveDownloadView(View* view) { diff --git a/chrome/browser/ui/views/download/download_shelf_view.h b/chrome/browser/ui/views/download/download_shelf_view.h index f3a22ce..8c9b13a 100644 --- a/chrome/browser/ui/views/download/download_shelf_view.h +++ b/chrome/browser/ui/views/download/download_shelf_view.h @@ -9,8 +9,8 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "chrome/browser/download/download_shelf.h" -#include "chrome/browser/ui/views/accessible_pane_view.h" #include "ui/base/animation/animation_delegate.h" +#include "views/accessible_pane_view.h" #include "views/controls/button/button.h" #include "views/controls/link_listener.h" #include "views/mouse_watcher.h" @@ -35,7 +35,7 @@ class ImageView; // // DownloadShelfView does not hold an infinite number of download views, rather // it'll automatically remove views once a certain point is reached. -class DownloadShelfView : public AccessiblePaneView, +class DownloadShelfView : public views::AccessiblePaneView, public ui::AnimationDelegate, public DownloadShelf, public views::ButtonListener, @@ -82,8 +82,10 @@ class DownloadShelfView : public AccessiblePaneView, virtual void MouseMovedOutOfView(); // Override views::FocusChangeListener method from AccessiblePaneView. - virtual void FocusWillChange(View* focused_before, - View* focused_now) OVERRIDE; + virtual void OnWillChangeFocus(View* focused_before, + View* focused_now) OVERRIDE; + virtual void OnDidChangeFocus(View* focused_before, + View* focused_now) OVERRIDE; // Removes a specified download view. The supplied view is deleted after // it's removed. diff --git a/chrome/browser/ui/views/dropdown_bar_host.cc b/chrome/browser/ui/views/dropdown_bar_host.cc index 437b97f..b1cc7aa 100644 --- a/chrome/browser/ui/views/dropdown_bar_host.cc +++ b/chrome/browser/ui/views/dropdown_bar_host.cc @@ -152,8 +152,8 @@ bool DropdownBarHost::IsVisible() const { //////////////////////////////////////////////////////////////////////////////// // DropdownBarHost, views::FocusChangeListener implementation: -void DropdownBarHost::FocusWillChange(views::View* focused_before, - views::View* focused_now) { +void DropdownBarHost::OnWillChangeFocus(views::View* focused_before, + views::View* focused_now) { // First we need to determine if one or both of the views passed in are child // views of our view. bool our_view_before = focused_before && view_->Contains(focused_before); @@ -175,6 +175,10 @@ void DropdownBarHost::FocusWillChange(views::View* focused_before, } } +void DropdownBarHost::OnDidChangeFocus(views::View* focused_before, + views::View* focused_now) { +} + //////////////////////////////////////////////////////////////////////////////// // DropdownBarHost, ui::AnimationDelegate implementation: diff --git a/chrome/browser/ui/views/dropdown_bar_host.h b/chrome/browser/ui/views/dropdown_bar_host.h index 8445549..4c5b5af 100644 --- a/chrome/browser/ui/views/dropdown_bar_host.h +++ b/chrome/browser/ui/views/dropdown_bar_host.h @@ -71,8 +71,10 @@ class DropdownBarHost : public views::AcceleratorTarget, virtual void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) = 0; // Overridden from views::FocusChangeListener: - virtual void FocusWillChange(views::View* focused_before, - views::View* focused_now); + virtual void OnWillChangeFocus(views::View* focused_before, + views::View* focused_now) OVERRIDE; + virtual void OnDidChangeFocus(views::View* focused_before, + views::View* focused_now) OVERRIDE; // Overridden from views::AcceleratorTarget: virtual bool AcceleratorPressed(const views::Accelerator& accelerator) = 0; diff --git a/chrome/browser/ui/views/dropdown_bar_view.h b/chrome/browser/ui/views/dropdown_bar_view.h index 7536a1b..900825e 100644 --- a/chrome/browser/ui/views/dropdown_bar_view.h +++ b/chrome/browser/ui/views/dropdown_bar_view.h @@ -8,7 +8,7 @@ #include "chrome/browser/ui/views/dropdown_bar_host.h" #include "chrome/browser/ui/views/dropdown_bar_host_delegate.h" -#include "chrome/browser/ui/views/accessible_pane_view.h" +#include "views/accessible_pane_view.h" namespace gfx { class Canvas; @@ -20,7 +20,7 @@ class Canvas; // DropdownBarHost. // //////////////////////////////////////////////////////////////////////////////// -class DropdownBarView : public AccessiblePaneView, +class DropdownBarView : public views::AccessiblePaneView, public DropdownBarHostDelegate { public: explicit DropdownBarView(DropdownBarHost* host); diff --git a/chrome/browser/ui/views/find_bar_host.cc b/chrome/browser/ui/views/find_bar_host.cc index db3041b..f2c822f 100644 --- a/chrome/browser/ui/views/find_bar_host.cc +++ b/chrome/browser/ui/views/find_bar_host.cc @@ -178,7 +178,7 @@ bool FindBarHost::AcceleratorPressed(const views::Accelerator& accelerator) { } else if (key == ui::VKEY_ESCAPE) { // This will end the Find session and hide the window, causing it to loose // focus and in the process unregister us as the handler for the Escape - // accelerator through the FocusWillChange event. + // accelerator through the OnWillChangeFocus event. find_bar_controller_->EndFindSession(FindBarController::kKeepSelection); } else { NOTREACHED() << "Unknown accelerator"; diff --git a/chrome/browser/ui/views/first_run_bubble.cc b/chrome/browser/ui/views/first_run_bubble.cc index ea925db..39e57e8f 100644 --- a/chrome/browser/ui/views/first_run_bubble.cc +++ b/chrome/browser/ui/views/first_run_bubble.cc @@ -65,6 +65,7 @@ class FirstRunBubbleViewBase : public views::View, // Called by FirstRunBubble::Show to request focus for the proper button // in the FirstRunBubbleView when it is shown. virtual void BubbleShown() = 0; + virtual void OnDidChangeFocus(View* focused_before, View* focused_now) {} }; // FirstRunBubbleView --------------------------------------------------------- @@ -85,7 +86,7 @@ class FirstRunBubbleView : public FirstRunBubbleViewBase { virtual gfx::Size GetPreferredSize(); // FocusChangeListener: - virtual void FocusWillChange(View* focused_before, View* focused_now); + virtual void OnWillChangeFocus(View* focused_before, View* focused_now); FirstRunBubble* bubble_window_; views::Label* label1_; @@ -217,8 +218,8 @@ gfx::Size FirstRunBubbleView::GetPreferredSize() { IDS_FIRSTRUNBUBBLE_DIALOG_HEIGHT_LINES)); } -void FirstRunBubbleView::FocusWillChange(View* focused_before, - View* focused_now) { +void FirstRunBubbleView::OnWillChangeFocus(View* focused_before, + View* focused_now) { if (focused_before && (focused_before->GetClassName() == views::NativeTextButton::kViewClassName)) { @@ -253,7 +254,7 @@ class FirstRunOEMBubbleView : public FirstRunBubbleViewBase { virtual gfx::Size GetPreferredSize(); // FocusChangeListener: - virtual void FocusWillChange(View* focused_before, View* focused_now); + virtual void OnWillChangeFocus(View* focused_before, View* focused_now); FirstRunBubble* bubble_window_; views::Label* label1_; @@ -381,8 +382,8 @@ gfx::Size FirstRunOEMBubbleView::GetPreferredSize() { return size; } -void FirstRunOEMBubbleView::FocusWillChange(View* focused_before, - View* focused_now) { +void FirstRunOEMBubbleView::OnWillChangeFocus(View* focused_before, + View* focused_now) { // No buttons in oem_bubble to register focus changes. } @@ -406,7 +407,7 @@ class FirstRunMinimalBubbleView : public FirstRunBubbleViewBase { virtual gfx::Size GetPreferredSize(); // FocusChangeListener: - virtual void FocusWillChange(View* focused_before, View* focused_now); + virtual void OnWillChangeFocus(View* focused_before, View* focused_now); FirstRunBubble* bubble_window_; Profile* profile_; @@ -477,8 +478,8 @@ gfx::Size FirstRunMinimalBubbleView::GetPreferredSize() { IDS_FIRSTRUN_MINIMAL_BUBBLE_DIALOG_HEIGHT_LINES)); } -void FirstRunMinimalBubbleView::FocusWillChange(View* focused_before, - View* focused_now) { +void FirstRunMinimalBubbleView::OnWillChangeFocus(View* focused_before, + View* focused_now) { // No buttons in minimal bubble to register focus changes. } diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 2e9d8ae..ca8f197 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -871,17 +871,14 @@ void BrowserView::UpdateToolbar(TabContentsWrapper* contents, } void BrowserView::FocusToolbar() { - // Start the traversal within the main toolbar, passing it the storage id - // of the view where focus should be returned if the user exits the toolbar. - SaveFocusedView(); - toolbar_->SetPaneFocus(last_focused_view_storage_id_, NULL); + // Start the traversal within the main toolbar. SetPaneFocus stores + // the current focused view before changing focus. + toolbar_->SetPaneFocus(NULL); } void BrowserView::FocusBookmarksToolbar() { - if (active_bookmark_bar_ && bookmark_bar_view_->IsVisible()) { - SaveFocusedView(); - bookmark_bar_view_->SetPaneFocus(last_focused_view_storage_id_, NULL); - } + if (active_bookmark_bar_ && bookmark_bar_view_->IsVisible()) + bookmark_bar_view_->SetPaneFocus(bookmark_bar_view_.get()); } void BrowserView::FocusAppMenu() { @@ -895,8 +892,7 @@ void BrowserView::FocusAppMenu() { if (toolbar_->IsAppMenuFocused()) { RestoreFocus(); } else { - SaveFocusedView(); - toolbar_->SetPaneFocusAndFocusAppMenu(last_focused_view_storage_id_); + toolbar_->SetPaneFocusAndFocusAppMenu(); } } @@ -911,7 +907,7 @@ void BrowserView::RotatePaneFocus(bool forwards) { // with NULL to represent the tab contents getting focus. If one of these // is currently invisible or has no focusable children it will be // automatically skipped. - std::vector<AccessiblePaneView*> accessible_panes; + std::vector<views::AccessiblePaneView*> accessible_panes; GetAccessiblePanes(&accessible_panes); int pane_count = static_cast<int>(accessible_panes.size()); @@ -940,7 +936,7 @@ void BrowserView::RotatePaneFocus(bool forwards) { // If the focus isn't currently in a pane, save the focus so we // can restore it if the user presses Escape. if (focused_view && index >= pane_count) - SaveFocusedView(); + GetFocusManager()->StoreFocusedView(); // Try to focus the next pane; if SetPaneFocusAndFocusDefault returns // false it means the pane didn't have any focusable controls, so skip @@ -952,10 +948,8 @@ void BrowserView::RotatePaneFocus(bool forwards) { index = ((index - 1) + count) % count; if (index < pane_count) { - if (accessible_panes[index]->SetPaneFocusAndFocusDefault( - last_focused_view_storage_id_)) { + if (accessible_panes[index]->SetPaneFocusAndFocusDefault()) break; - } } else { accessible_views[index]->RequestFocus(); break; @@ -963,15 +957,6 @@ void BrowserView::RotatePaneFocus(bool forwards) { } } -void BrowserView::SaveFocusedView() { - views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); - if (view_storage->RetrieveView(last_focused_view_storage_id_)) - view_storage->RemoveView(last_focused_view_storage_id_); - views::View* focused_view = GetFocusManager()->GetFocusedView(); - if (focused_view) - view_storage->StoreView(last_focused_view_storage_id_, focused_view); -} - void BrowserView::DestroyBrowser() { // After this returns other parts of Chrome are going to be shutdown. Close // the window now so that we are deleted immediately and aren't left holding @@ -1725,7 +1710,7 @@ gfx::Size BrowserView::GetMinimumSize() { // BrowserView, protected void BrowserView::GetAccessiblePanes( - std::vector<AccessiblePaneView*>* panes) { + std::vector<views::AccessiblePaneView*>* panes) { // This should be in the order of pane traversal of the panes using F6. // If one of these is invisible or has no focusable children, it will be // automatically skipped. diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index beae7bb..a3a5415 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -38,7 +38,6 @@ // NOTE: For more information about the objects and files in this directory, // view: http://dev.chromium.org/developers/design-documents/browser-window -class AccessiblePaneView; class BookmarkBarView; class Browser; class BrowserBubble; @@ -68,6 +67,7 @@ class LauncherIconUpdater; #endif namespace views { +class AccessiblePaneView; class ExternalFocusTracker; class Menu; } @@ -415,10 +415,7 @@ class BrowserView : public BrowserBubbleHost, // can be traversed using F6, in the order they should be traversed. // Abstracted here so that it can be extended for Chrome OS. virtual void GetAccessiblePanes( - std::vector<AccessiblePaneView*>* panes); - - // Save the current focused view to view storage - void SaveFocusedView(); + std::vector<views::AccessiblePaneView*>* panes); int last_focused_view_storage_id() const { return last_focused_view_storage_id_; diff --git a/chrome/browser/ui/views/infobars/infobar_container_view.h b/chrome/browser/ui/views/infobars/infobar_container_view.h index 2e2d552c..9ee2d69 100644 --- a/chrome/browser/ui/views/infobars/infobar_container_view.h +++ b/chrome/browser/ui/views/infobars/infobar_container_view.h @@ -7,10 +7,10 @@ #pragma once #include "chrome/browser/infobars/infobar_container.h" -#include "chrome/browser/ui/views/accessible_pane_view.h" +#include "views/accessible_pane_view.h" // The views-specific implementation of InfoBarContainer. -class InfoBarContainerView : public AccessiblePaneView, +class InfoBarContainerView : public views::AccessiblePaneView, public InfoBarContainer { public: explicit InfoBarContainerView(Delegate* delegate); diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index 3175160..3989847 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -375,7 +375,7 @@ gfx::Size InfoBarView::GetPreferredSize() { return gfx::Size(0, total_height()); } -void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { +void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { // This will trigger some screen readers to read the entire contents of this // infobar. if (focused_before && focused_now && !Contains(focused_before) && @@ -384,3 +384,6 @@ void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { this, ui::AccessibilityTypes::EVENT_ALERT, true); } } + +void InfoBarView::OnDidChangeFocus(View* focused_before, View* focused_now) { +} diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h index 709ade6..8707377 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.h +++ b/chrome/browser/ui/views/infobars/infobar_view.h @@ -113,8 +113,10 @@ class InfoBarView : public InfoBar, virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; // views::FocusChangeListener: - virtual void FocusWillChange(View* focused_before, - View* focused_now) OVERRIDE; + virtual void OnWillChangeFocus(View* focused_before, + View* focused_now) OVERRIDE; + virtual void OnDidChangeFocus(View* focused_before, + View* focused_now) OVERRIDE; // The optional icon at the left edge of the InfoBar. views::ImageView* icon_; diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 6a13820..158738d 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -350,7 +350,7 @@ void LocationBarView::OnFocus() { // Then focus the native location view which implements accessibility for // Windows. - location_entry_->SetFocus(); + FocusLocation(true); } void LocationBarView::SetPreviewEnabledPageAction(ExtensionAction* page_action, @@ -1138,8 +1138,7 @@ void LocationBarView::AcceptInput() { void LocationBarView::FocusLocation(bool select_all) { location_entry_->SetFocus(); - if (select_all) - location_entry_->SelectAll(true); + location_entry_->SelectAll(select_all); } void LocationBarView::FocusSearch() { diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index 6719871..28ae57e 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -50,6 +50,7 @@ class TabContentsWrapper; class TemplateURLService; namespace views { +class Accelerator; class HorizontalPainter; class Label; } // namespace views diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index 5bfead8..6da0619 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -229,12 +229,12 @@ void ToolbarView::Update(TabContents* tab, bool should_restore_state) { browser_actions_->RefreshBrowserActionViews(); } -void ToolbarView::SetPaneFocusAndFocusLocationBar(int view_storage_id) { - SetPaneFocus(view_storage_id, location_bar_); +void ToolbarView::SetPaneFocusAndFocusLocationBar() { + SetPaneFocus(location_bar_); } -void ToolbarView::SetPaneFocusAndFocusAppMenu(int view_storage_id) { - SetPaneFocus(view_storage_id, app_menu_); +void ToolbarView::SetPaneFocusAndFocusAppMenu() { + SetPaneFocus(app_menu_); } bool ToolbarView::IsAppMenuFocused() { @@ -313,9 +313,8 @@ SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { //////////////////////////////////////////////////////////////////////////////// // ToolbarView, AccessiblePaneView overrides: -bool ToolbarView::SetPaneFocus( - int view_storage_id, views::View* initial_focus) { - if (!AccessiblePaneView::SetPaneFocus(view_storage_id, initial_focus)) +bool ToolbarView::SetPaneFocus(views::View* initial_focus) { + if (!AccessiblePaneView::SetPaneFocus(initial_focus)) return false; location_bar_->SetShowFocusRect(true); @@ -633,6 +632,13 @@ std::string ToolbarView::GetClassName() const { return kViewClassName; } +bool ToolbarView::AcceleratorPressed(const views::Accelerator& accelerator) { + const views::View* focused_view = focus_manager_->GetFocusedView(); + if (focused_view == location_bar_) + return false; // Let location bar handle all accelerator events. + return AccessiblePaneView::AcceleratorPressed(accelerator); +} + //////////////////////////////////////////////////////////////////////////////// // ToolbarView, protected: diff --git a/chrome/browser/ui/views/toolbar_view.h b/chrome/browser/ui/views/toolbar_view.h index 48d45a4..d8fb914 100644 --- a/chrome/browser/ui/views/toolbar_view.h +++ b/chrome/browser/ui/views/toolbar_view.h @@ -14,11 +14,11 @@ #include "chrome/browser/command_updater.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" -#include "chrome/browser/ui/views/accessible_pane_view.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "chrome/browser/ui/views/reload_button.h" #include "ui/base/animation/slide_animation.h" #include "ui/base/models/accelerator.h" +#include "views/accessible_pane_view.h" #include "views/controls/button/menu_button.h" #include "views/controls/menu/view_menu_delegate.h" #include "views/view.h" @@ -33,7 +33,7 @@ class MenuListener; } // The Browser Window's toolbar. -class ToolbarView : public AccessiblePaneView, +class ToolbarView : public views::AccessiblePaneView, public views::ViewMenuDelegate, public ui::AcceleratorProvider, public LocationBarView::Delegate, @@ -58,13 +58,13 @@ class ToolbarView : public AccessiblePaneView, // Set focus to the toolbar with complete keyboard access, with the // focus initially set to the location bar. Focus will be restored - // to the ViewStorage with id |view_storage_id| if the user escapes. - void SetPaneFocusAndFocusLocationBar(int view_storage_id); + // to the last focused view if the user escapes. + void SetPaneFocusAndFocusLocationBar(); // Set focus to the toolbar with complete keyboard access, with the // focus initially set to the app menu. Focus will be restored - // to the ViewStorage with id |view_storage_id| if the user escapes. - void SetPaneFocusAndFocusAppMenu(int view_storage_id); + // to the last focused view if the user escapes. + void SetPaneFocusAndFocusAppMenu(); // Returns true if the app menu is focused. bool IsAppMenuFocused(); @@ -89,7 +89,7 @@ class ToolbarView : public AccessiblePaneView, views::MenuButton* app_menu() const { return app_menu_; } // Overridden from AccessiblePaneView - virtual bool SetPaneFocus(int view_storage_id, View* initial_focus) OVERRIDE; + virtual bool SetPaneFocus(View* initial_focus) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; // Overridden from views::ViewMenuDelegate: @@ -128,6 +128,7 @@ class ToolbarView : public AccessiblePaneView, virtual int OnPerformDrop(const views::DropTargetEvent& event) OVERRIDE; virtual void OnThemeChanged() OVERRIDE; virtual std::string GetClassName() const OVERRIDE; + virtual bool AcceleratorPressed(const views::Accelerator& acc) OVERRIDE; // The apparent horizontal space between most items, and the vertical padding // above and below them. diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 4413b044..923aab6 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3245,8 +3245,6 @@ 'browser/ui/views/accelerator_table.h', 'browser/ui/views/accessibility_event_router_views.cc', 'browser/ui/views/accessibility_event_router_views.h', - 'browser/ui/views/accessible_pane_view.cc', - 'browser/ui/views/accessible_pane_view.h', 'browser/ui/views/app_menu_button_win.cc', 'browser/ui/views/app_menu_button_win.h', 'browser/ui/views/appcache_info_view.cc', @@ -4646,8 +4644,6 @@ ['include', '^browser/ui/views/about_chrome_view.h'], ['include', '^browser/ui/views/accessibility_event_router_views.cc'], ['include', '^browser/ui/views/accessibility_event_router_views.h'], - ['include', '^browser/ui/views/accessible_pane_view.cc'], - ['include', '^browser/ui/views/accessible_pane_view.h'], ['include', '^browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc'], ['include', '^browser/ui/views/autocomplete/autocomplete_popup_contents_view.h'], ['include', '^browser/ui/views/autocomplete/autocomplete_result_view.cc'], diff --git a/chrome/browser/ui/views/accessible_pane_view.cc b/views/accessible_pane_view.cc index 90e68d0..437bdba 100644 --- a/chrome/browser/ui/views/accessible_pane_view.cc +++ b/views/accessible_pane_view.cc @@ -2,21 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/views/accessible_pane_view.h" +#include "views/accessible_pane_view.h" -#include "base/bind.h" -#include "base/logging.h" -#include "chrome/browser/ui/view_ids.h" -#include "chrome/browser/ui/views/frame/browser_view.h" -#include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "ui/base/accessibility/accessible_view_state.h" -#include "views/controls/button/menu_button.h" -#include "views/controls/native/native_view_host.h" #include "views/focus/focus_search.h" #include "views/focus/view_storage.h" -#include "views/widget/tooltip_manager.h" #include "views/widget/widget.h" +namespace views { + AccessiblePaneView::AccessiblePaneView() : pane_has_focus_(false), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), @@ -25,8 +19,7 @@ AccessiblePaneView::AccessiblePaneView() end_key_(ui::VKEY_END, false, false, false), escape_key_(ui::VKEY_ESCAPE, false, false, false), left_key_(ui::VKEY_LEFT, false, false, false), - right_key_(ui::VKEY_RIGHT, false, false, false), - last_focused_view_storage_id_(-1) { + right_key_(ui::VKEY_RIGHT, false, false, false) { focus_search_.reset(new views::FocusSearch(this, true, true)); } @@ -36,18 +29,15 @@ AccessiblePaneView::~AccessiblePaneView() { } } -bool AccessiblePaneView::SetPaneFocus(int view_storage_id, - views::View* initial_focus) { +bool AccessiblePaneView::SetPaneFocus(views::View* initial_focus) { if (!IsVisible()) return false; - // Save the storage id to the last focused view. This would be used to request - // focus to the view when the traversal is ended. - last_focused_view_storage_id_ = view_storage_id; - if (!focus_manager_) focus_manager_ = GetFocusManager(); + focus_manager_->StoreFocusedView(); + // Use the provided initial focus if it's visible and enabled, otherwise // use the first focusable child. if (!initial_focus || @@ -61,13 +51,7 @@ bool AccessiblePaneView::SetPaneFocus(int view_storage_id, if (!initial_focus) return false; - // Set focus to the initial view. If it's a location bar, use a special - // method that tells it to select all, also. - if (initial_focus->GetClassName() == LocationBarView::kViewClassName) { - static_cast<LocationBarView*>(initial_focus)->FocusLocation(true); - } else { - focus_manager_->SetFocusedView(initial_focus); - } + focus_manager_->SetFocusedView(initial_focus); // If we already have pane focus, we're done. if (pane_has_focus_) @@ -85,9 +69,8 @@ bool AccessiblePaneView::SetPaneFocus(int view_storage_id, return true; } -bool AccessiblePaneView::SetPaneFocusAndFocusDefault( - int view_storage_id) { - return SetPaneFocus(view_storage_id, GetDefaultFocusableChild()); +bool AccessiblePaneView::SetPaneFocusAndFocusDefault() { + return SetPaneFocus(GetDefaultFocusableChild()); } views::View* AccessiblePaneView::GetDefaultFocusableChild() { @@ -105,31 +88,6 @@ void AccessiblePaneView::RemovePaneFocus() { focus_manager_->UnregisterAccelerator(right_key_, this); } -void AccessiblePaneView::LocationBarSelectAll() { - views::View* focused_view = GetFocusManager()->GetFocusedView(); - if (focused_view && - focused_view->GetClassName() == LocationBarView::kViewClassName) { - static_cast<LocationBarView*>(focused_view)->SelectAll(); - } -} - -void AccessiblePaneView::RestoreLastFocusedView() { - views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); - views::View* last_focused_view = - view_storage->RetrieveView(last_focused_view_storage_id_); - if (last_focused_view) { - focus_manager_->SetFocusedViewWithReason( - last_focused_view, views::FocusManager::kReasonFocusRestore); - } else { - // Focus the location bar - views::View* view = GetAncestorWithClassName(BrowserView::kViewClassName); - if (view) { - BrowserView* browser_view = static_cast<BrowserView*>(view); - browser_view->SetFocusToLocationBar(false); - } - } -} - views::View* AccessiblePaneView::GetFirstFocusableChild() { FocusTraversable* dummy_focus_traversable; views::View* dummy_focus_traversable_view; @@ -158,19 +116,15 @@ views::FocusTraversable* AccessiblePaneView::GetPaneFocusTraversable() { bool AccessiblePaneView::AcceleratorPressed( const views::Accelerator& accelerator) { - // Special case: don't handle any accelerators for the location bar, - // so that it behaves exactly the same whether you focus it with Ctrl+L - // or F6 or Alt+D or Alt+Shift+T. + const views::View* focused_view = focus_manager_->GetFocusedView(); - if ((focused_view->GetClassName() == LocationBarView::kViewClassName || - focused_view->GetClassName() == views::NativeViewHost::kViewClassName)) { + if (!Contains(focused_view)) return false; - } switch (accelerator.key_code()) { case ui::VKEY_ESCAPE: RemovePaneFocus(); - RestoreLastFocusedView(); + focus_manager_->RestoreFocusedView(); return true; case ui::VKEY_LEFT: focus_manager_->AdvanceFocus(true); @@ -194,7 +148,7 @@ bool AccessiblePaneView::AcceleratorPressed( void AccessiblePaneView::SetVisible(bool flag) { if (IsVisible() && !flag && pane_has_focus_) { RemovePaneFocus(); - RestoreLastFocusedView(); + focus_manager_->RestoreFocusedView(); } View::SetVisible(flag); } @@ -206,38 +160,26 @@ void AccessiblePaneView::GetAccessibleState(ui::AccessibleViewState* state) { //////////////////////////////////////////////////////////////////////////////// // FocusChangeListener overrides: -void AccessiblePaneView::FocusWillChange(views::View* focused_before, - views::View* focused_now) { +void AccessiblePaneView::OnWillChangeFocus(views::View* focused_before, + views::View* focused_now) { + // Act when focus has changed. +} + +void AccessiblePaneView::OnDidChangeFocus(views::View* focused_before, + views::View* focused_now) { if (!focused_now) return; views::FocusManager::FocusChangeReason reason = focus_manager_->focus_change_reason(); - if (focused_now->GetClassName() == LocationBarView::kViewClassName && - reason == views::FocusManager::kReasonFocusTraversal) { - // Tabbing to the location bar should select all. Defer so that it happens - // after the focus. - MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&AccessiblePaneView::LocationBarSelectAll, - method_factory_.GetWeakPtr())); - } - if (!Contains(focused_now) || reason == views::FocusManager::kReasonDirectFocusChange) { // We should remove pane focus (i.e. make most of the controls - // not focusable again) either because the focus is leaving the pane, + // not focusable again) because the focus has left the pane, // or because the focus changed within the pane due to the user // directly focusing to a specific view (e.g., clicking on it). - // - // Defer rather than calling RemovePaneFocus right away, because we can't - // remove |this| as a focus change listener while FocusManager is in the - // middle of iterating over the list of listeners. - MessageLoop::current()->PostTask( - FROM_HERE, - base::Bind(&AccessiblePaneView::RemovePaneFocus, - method_factory_.GetWeakPtr())); + RemovePaneFocus(); } } @@ -258,3 +200,5 @@ views::View* AccessiblePaneView::GetFocusTraversableParentView() { DCHECK(pane_has_focus_); return NULL; } + +} // namespace views diff --git a/chrome/browser/ui/views/accessible_pane_view.h b/views/accessible_pane_view.h index d8d0b2b..140590c 100644 --- a/chrome/browser/ui/views/accessible_pane_view.h +++ b/views/accessible_pane_view.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_ +#ifndef VIEWS_ACCESSIBLE_PANE_VIEW_H_ +#define VIEWS_ACCESSIBLE_PANE_VIEW_H_ #pragma once #include "base/hash_tables.h" @@ -14,59 +14,57 @@ namespace views { class FocusSearch; -} // This class provides keyboard access to any view that extends it, typically // a toolbar. The user sets focus to a control in this view by pressing // F6 to traverse all panes, or by pressing a shortcut that jumps directly // to this pane. -class AccessiblePaneView : public views::View, - public views::FocusChangeListener, - public views::FocusTraversable { +class AccessiblePaneView : public View, + public FocusChangeListener, + public FocusTraversable { public: AccessiblePaneView(); virtual ~AccessiblePaneView(); // Set focus to the pane with complete keyboard access. - // Focus will be restored to the ViewStorage with id |view_storage_id| - // if the user escapes. If |initial_focus| is not NULL, that control will get + // Focus will be restored to the last focused view if the user escapes. + // If |initial_focus| is not NULL, that control will get // the initial focus, if it's enabled and focusable. Returns true if // the pane was able to receive focus. - virtual bool SetPaneFocus(int view_storage_id, View* initial_focus); + virtual bool SetPaneFocus(View* initial_focus); // Set focus to the pane with complete keyboard access, with the // focus initially set to the default child. Focus will be restored - // to the ViewStorage with id |view_storage_id| if the user escapes. + // to the last focused view if the user escapes. // Returns true if the pane was able to receive focus. - virtual bool SetPaneFocusAndFocusDefault(int view_storage_id); + virtual bool SetPaneFocusAndFocusDefault(); - // Overridden from views::View: + // Overridden from View: virtual FocusTraversable* GetPaneFocusTraversable() OVERRIDE; - virtual bool AcceleratorPressed(const views::Accelerator& accelerator) + virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; virtual void SetVisible(bool flag) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; - // Overridden from views::FocusChangeListener: - virtual void FocusWillChange(View* focused_before, - View* focused_now) OVERRIDE; + // Overridden from FocusChangeListener: + virtual void OnWillChangeFocus(View* focused_before, + View* focused_now) OVERRIDE; + virtual void OnDidChangeFocus(View* focused_before, + View* focused_now) OVERRIDE; - // Overridden from views::FocusTraversable: - virtual views::FocusSearch* GetFocusSearch() OVERRIDE; + // Overridden from FocusTraversable: + virtual FocusSearch* GetFocusSearch() OVERRIDE; virtual FocusTraversable* GetFocusTraversableParent() OVERRIDE; virtual View* GetFocusTraversableParentView() OVERRIDE; protected: // A subclass can override this to provide a default focusable child // other than the first focusable child. - virtual views::View* GetDefaultFocusableChild(); + virtual View* GetDefaultFocusableChild(); // Remove pane focus. virtual void RemovePaneFocus(); - // Select all text in the location bar - virtual void LocationBarSelectAll(); - void RestoreLastFocusedView(); View* GetFirstFocusableChild(); @@ -78,24 +76,23 @@ class AccessiblePaneView : public views::View, // Save the focus manager rather than calling GetFocusManager(), // so that we can remove focus listeners in the destructor. - views::FocusManager* focus_manager_; + FocusManager* focus_manager_; // Our custom focus search implementation that traps focus in this // pane and traverses all views that are focusable for accessibility, // not just those that are normally focusable. - scoped_ptr<views::FocusSearch> focus_search_; + scoped_ptr<FocusSearch> focus_search_; // Registered accelerators - views::Accelerator home_key_; - views::Accelerator end_key_; - views::Accelerator escape_key_; - views::Accelerator left_key_; - views::Accelerator right_key_; - - // Last focused view that issued this traversal. - int last_focused_view_storage_id_; + Accelerator home_key_; + Accelerator end_key_; + Accelerator escape_key_; + Accelerator left_key_; + Accelerator right_key_; DISALLOW_COPY_AND_ASSIGN(AccessiblePaneView); }; -#endif // CHROME_BROWSER_UI_VIEWS_ACCESSIBLE_PANE_VIEW_H_ +} // namespace views + +#endif // VIEWS_ACCESSIBLE_PANE_VIEW_H_ diff --git a/views/accessible_pane_view_unittest.cc b/views/accessible_pane_view_unittest.cc new file mode 100644 index 0000000..5d86ab89 --- /dev/null +++ b/views/accessible_pane_view_unittest.cc @@ -0,0 +1,177 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "views/accessible_pane_view.h" + +#include "views/controls/button/text_button.h" +#include "views/layout/fill_layout.h" +#include "views/test/views_test_base.h" +#include "views/widget/widget.h" + +namespace views { + +// TODO(alicet): bring pane rotation into views and add tests. +// See browser_view.cc for details. + +typedef ViewsTestBase AccessiblePaneViewTest; + +class TestBarView : public AccessiblePaneView, + public ButtonListener { + public: + TestBarView(); + virtual ~TestBarView(); + + virtual void ButtonPressed(Button* sender, + const views::Event& event) OVERRIDE; + TextButton* child_button() const { return child_button_.get(); } + TextButton* second_child_button() const { return second_child_button_.get(); } + TextButton* third_child_button() const { return third_child_button_.get(); } + TextButton* not_child_button() const { return not_child_button_.get(); } + + const Accelerator& home_key() const { return home_key_; } + const Accelerator& end_key() const { return end_key_; } + const Accelerator& escape_key() const { return escape_key_; } + const Accelerator& left_key() const { return left_key_; } + const Accelerator& right_key() const { return right_key_; } + + virtual View* GetDefaultFocusableChild() OVERRIDE; + + private: + void Init(); + + scoped_ptr<TextButton> child_button_; + scoped_ptr<TextButton> second_child_button_; + scoped_ptr<TextButton> third_child_button_; + scoped_ptr<TextButton> not_child_button_; + + DISALLOW_COPY_AND_ASSIGN(TestBarView); +}; + +TestBarView::TestBarView() { + Init(); +} + +TestBarView::~TestBarView() {} + +void TestBarView::ButtonPressed(views::Button* sender, + const views::Event& event) {} + +void TestBarView::Init() { + SetLayoutManager(new views::FillLayout()); + string16 label; + child_button_.reset(new TextButton(this, label)); + AddChildView(child_button_.get()); + second_child_button_.reset(new TextButton(this, label)); + AddChildView(second_child_button_.get()); + third_child_button_.reset(new TextButton(this, label)); + AddChildView(third_child_button_.get()); + not_child_button_.reset(new TextButton(this, label)); +} + +View* TestBarView::GetDefaultFocusableChild() { + return child_button_.get(); +} + +TEST_F(AccessiblePaneViewTest, SimpleSetPaneFocus) { + TestBarView* test_view = new TestBarView(); + scoped_ptr<Widget> widget(new Widget()); + Widget::InitParams params(Widget::InitParams::TYPE_POPUP); + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + params.bounds = gfx::Rect(50, 50, 650, 650); + widget->Init(params); + View* root = widget->GetRootView(); + root->AddChildView(test_view); + widget->Show(); + + // Set pane focus succeeds, focus on child. + EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); + EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); + EXPECT_EQ(test_view->child_button(), + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + + // Set focus on non child view, focus failed, stays on pane. + EXPECT_TRUE(test_view->SetPaneFocus(test_view->not_child_button())); + EXPECT_FALSE(test_view->not_child_button() == + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + EXPECT_EQ(test_view->child_button(), + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + widget->CloseNow(); + widget.reset(); +} + +TEST_F(AccessiblePaneViewTest, TwoSetPaneFocus) { + TestBarView* test_view = new TestBarView(); + TestBarView* test_view_2 = new TestBarView(); + scoped_ptr<Widget> widget(new Widget()); + Widget::InitParams params(Widget::InitParams::TYPE_POPUP); + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + params.bounds = gfx::Rect(50, 50, 650, 650); + widget->Init(params); + View* root = widget->GetRootView(); + root->AddChildView(test_view); + root->AddChildView(test_view_2); + widget->Show(); + + // Set pane focus succeeds, focus on child. + EXPECT_TRUE(test_view->SetPaneFocusAndFocusDefault()); + EXPECT_EQ(test_view, test_view->GetPaneFocusTraversable()); + EXPECT_EQ(test_view->child_button(), + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + + // Set focus on another test_view, focus move to that pane. + EXPECT_TRUE(test_view_2->SetPaneFocus(test_view_2->second_child_button())); + EXPECT_FALSE(test_view->child_button() == + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + EXPECT_EQ(test_view_2->second_child_button(), + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + widget->CloseNow(); + widget.reset(); +} + +TEST_F(AccessiblePaneViewTest, PaneFocusTraversal) { + TestBarView* test_view = new TestBarView(); + TestBarView* original_test_view = new TestBarView(); + scoped_ptr<Widget> widget(new Widget()); + Widget::InitParams params(Widget::InitParams::TYPE_POPUP); + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + params.bounds = gfx::Rect(50, 50, 650, 650); + widget->Init(params); + View* root = widget->GetRootView(); + root->AddChildView(original_test_view); + root->AddChildView(test_view); + widget->Show(); + + // Set pane focus on first view. + EXPECT_TRUE(original_test_view->SetPaneFocus( + original_test_view->third_child_button())); + + // Test travesal in second view. + // Set pane focus on second child. + EXPECT_TRUE(test_view->SetPaneFocus(test_view->second_child_button())); + // home + test_view->AcceleratorPressed(test_view->home_key()); + EXPECT_EQ(test_view->child_button(), + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + // end + test_view->AcceleratorPressed(test_view->end_key()); + EXPECT_EQ(test_view->third_child_button(), + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + // left + test_view->AcceleratorPressed(test_view->left_key()); + EXPECT_EQ(test_view->second_child_button(), + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + // right, right + test_view->AcceleratorPressed(test_view->right_key()); + test_view->AcceleratorPressed(test_view->right_key()); + EXPECT_EQ(test_view->child_button(), + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + + // ESC + test_view->AcceleratorPressed(test_view->escape_key()); + EXPECT_EQ(original_test_view->third_child_button(), + test_view->GetWidget()->GetFocusManager()->GetFocusedView()); + widget->CloseNow(); + widget.reset(); +} +} // namespace views diff --git a/views/focus/external_focus_tracker.cc b/views/focus/external_focus_tracker.cc index 6af74d6..193b57e 100644 --- a/views/focus/external_focus_tracker.cc +++ b/views/focus/external_focus_tracker.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,8 +28,8 @@ ExternalFocusTracker::~ExternalFocusTracker() { focus_manager_->RemoveFocusChangeListener(this); } -void ExternalFocusTracker::FocusWillChange(View* focused_before, - View* focused_now) { +void ExternalFocusTracker::OnWillChangeFocus(View* focused_before, + View* focused_now) { if (focused_now && !parent_view_->Contains(focused_now) && parent_view_ != focused_now) { // Store the newly focused view. @@ -37,6 +37,10 @@ void ExternalFocusTracker::FocusWillChange(View* focused_before, } } +void ExternalFocusTracker::OnDidChangeFocus(View* focused_before, + View* focused_now) { +} + void ExternalFocusTracker::FocusLastFocusedExternalView() { View* last_focused_view = view_storage_->RetrieveView(last_focused_view_storage_id_); diff --git a/views/focus/external_focus_tracker.h b/views/focus/external_focus_tracker.h index 7bce179..62f553b 100644 --- a/views/focus/external_focus_tracker.h +++ b/views/focus/external_focus_tracker.h @@ -32,7 +32,8 @@ class VIEWS_EXPORT ExternalFocusTracker : public FocusChangeListener { virtual ~ExternalFocusTracker(); // FocusChangeListener implementation. - virtual void FocusWillChange(View* focused_before, View* focused_now); + virtual void OnWillChangeFocus(View* focused_before, View* focused_now); + virtual void OnDidChangeFocus(View* focused_before, View* focused_now); // Focuses last focused view which is not a child of parent view and is not // parent view itself. Returns true if focus for a view was requested, false diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc index 82eddf4..9697597 100644 --- a/views/focus/focus_manager.cc +++ b/views/focus/focus_manager.cc @@ -233,7 +233,7 @@ void FocusManager::SetFocusedViewWithReason( // some listeners), then notify all listeners. focus_change_reason_ = reason; FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, - FocusWillChange(focused_view_, view)); + OnWillChangeFocus(focused_view_, view)); View* old_focused_view = focused_view_; focused_view_ = view; @@ -241,6 +241,9 @@ void FocusManager::SetFocusedViewWithReason( old_focused_view->Blur(); if (focused_view_) focused_view_->Focus(); + + FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, + OnDidChangeFocus(old_focused_view, focused_view_)); } void FocusManager::ClearFocus() { diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h index 484e441..0fa5139 100644 --- a/views/focus/focus_manager.h +++ b/views/focus/focus_manager.h @@ -99,10 +99,13 @@ class VIEWS_EXPORT FocusTraversable { // This interface should be implemented by classes that want to be notified when // the focus is about to change. See the Add/RemoveFocusChangeListener methods. -// No change to focus state has occurred yet when this function is called. class VIEWS_EXPORT FocusChangeListener { public: - virtual void FocusWillChange(View* focused_before, View* focused_now) = 0; + // No change to focus state has occurred yet when this function is called. + virtual void OnWillChangeFocus(View* focused_before, View* focused_now) = 0; + + // Called after focus state has changed. + virtual void OnDidChangeFocus(View* focused_before, View* focused_now) = 0; protected: virtual ~FocusChangeListener() {} diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc index b2497e3..574182d 100644 --- a/views/focus/focus_manager_unittest.cc +++ b/views/focus/focus_manager_unittest.cc @@ -820,9 +820,11 @@ TEST_F(FocusManagerTest, ViewFocusCallbacks) { typedef std::pair<View*, View*> ViewPair; class TestFocusChangeListener : public FocusChangeListener { public: - virtual void FocusWillChange(View* focused_before, View* focused_now) { + virtual void OnWillChangeFocus(View* focused_before, View* focused_now) { focus_changes_.push_back(ViewPair(focused_before, focused_now)); } + virtual void OnDidChangeFocus(View* focused_before, View* focused_now) { + } const std::vector<ViewPair>& focus_changes() const { return focus_changes_; } void ClearFocusChanges() { focus_changes_.clear(); } diff --git a/views/focus/widget_focus_manager.cc b/views/focus/widget_focus_manager.cc index 3ff0a17..57cd2cd 100644 --- a/views/focus/widget_focus_manager.cc +++ b/views/focus/widget_focus_manager.cc @@ -29,7 +29,7 @@ void WidgetFocusManager::OnWidgetFocusEvent(gfx::NativeView focused_before, gfx::NativeView focused_now) { if (enabled_) { FOR_EACH_OBSERVER(WidgetFocusChangeListener, focus_change_listeners_, - NativeFocusWillChange(focused_before, focused_now)); + OnNativeFocusChange(focused_before, focused_now)); } } diff --git a/views/focus/widget_focus_manager.h b/views/focus/widget_focus_manager.h index ed430bc..503a158 100644 --- a/views/focus/widget_focus_manager.h +++ b/views/focus/widget_focus_manager.h @@ -22,8 +22,8 @@ namespace views { // children of a single top-level native-view. class WidgetFocusChangeListener { public: - virtual void NativeFocusWillChange(gfx::NativeView focused_before, - gfx::NativeView focused_now) = 0; + virtual void OnNativeFocusChange(gfx::NativeView focused_before, + gfx::NativeView focused_now) = 0; protected: virtual ~WidgetFocusChangeListener() {} diff --git a/views/ime/input_method_base.cc b/views/ime/input_method_base.cc index d494279..6155ccd 100644 --- a/views/ime/input_method_base.cc +++ b/views/ime/input_method_base.cc @@ -14,7 +14,6 @@ namespace views { InputMethodBase::InputMethodBase() : delegate_(NULL), widget_(NULL), - focused_view_(NULL), widget_focused_(false) { } @@ -40,9 +39,11 @@ void InputMethodBase::Init(Widget* widget) { } widget_ = widget; + // The InputMethod is lazily created, so we need to tell it the currently + // focused view. View* focused = widget->GetFocusManager()->GetFocusedView(); if (focused) - FocusWillChange(NULL, focused); + OnWillChangeFocus(NULL, focused); widget->GetFocusManager()->AddFocusChangeListener(this); } @@ -58,6 +59,10 @@ void InputMethodBase::OnBlur() { GetTextInputType(), widget_); } +views::View* InputMethodBase::GetFocusedView() const { + return widget_->GetFocusManager()->GetFocusedView(); +} + void InputMethodBase::OnTextInputTypeChanged(View* view) { if (IsViewFocused(view)) { TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( @@ -66,8 +71,8 @@ void InputMethodBase::OnTextInputTypeChanged(View* view) { } TextInputClient* InputMethodBase::GetTextInputClient() const { - return (widget_focused_ && focused_view_) ? - focused_view_->GetTextInputClient() : NULL; + return (widget_focused_ && GetFocusedView()) ? + GetFocusedView()->GetTextInputClient() : NULL; } ui::TextInputType InputMethodBase::GetTextInputType() const { @@ -79,12 +84,10 @@ bool InputMethodBase::IsMock() const { return false; } -void InputMethodBase::FocusWillChange(View* focused_before, View* focused) { - DCHECK_EQ(focused_view_, focused_before); - FocusedViewWillChange(); - focused_view_ = focused; - FocusedViewDidChange(); +void InputMethodBase::OnWillChangeFocus(View* focused_before, View* focused) { +} +void InputMethodBase::OnDidChangeFocus(View* focused_before, View* focused) { if (widget_focused_) { TextInputTypeTracker::GetInstance()->OnTextInputTypeChanged( GetTextInputType(), widget_); @@ -92,7 +95,7 @@ void InputMethodBase::FocusWillChange(View* focused_before, View* focused) { } bool InputMethodBase::IsViewFocused(View* view) const { - return widget_focused_ && view && focused_view_ == view; + return widget_focused_ && view && GetFocusedView() == view; } bool InputMethodBase::IsTextInputTypeNone() const { @@ -116,19 +119,12 @@ bool InputMethodBase::GetCaretBoundsInWidget(gfx::Rect* rect) const { if (!client || client->GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) return false; - *rect = focused_view_->ConvertRectToWidget(client->GetCaretBounds()); + *rect = GetFocusedView()->ConvertRectToWidget(client->GetCaretBounds()); // We need to do coordinate conversion if the focused view is inside a child // Widget. - if (focused_view_->GetWidget() != widget_) - return Widget::ConvertRect(focused_view_->GetWidget(), widget_, rect); + if (GetFocusedView()->GetWidget() != widget_) + return Widget::ConvertRect(GetFocusedView()->GetWidget(), widget_, rect); return true; } - -void InputMethodBase::FocusedViewWillChange() { -} - -void InputMethodBase::FocusedViewDidChange() { -} - } // namespace views diff --git a/views/ime/input_method_base.h b/views/ime/input_method_base.h index f8e232d..e657e22 100644 --- a/views/ime/input_method_base.h +++ b/views/ime/input_method_base.h @@ -50,17 +50,16 @@ class VIEWS_EXPORT InputMethodBase : public InputMethod, virtual ui::TextInputType GetTextInputType() const OVERRIDE; virtual bool IsMock() const OVERRIDE; - // Overridden from FocusChangeListener. Derived classes shouldn't override - // this method. Override FocusedViewWillChange() and FocusedViewDidChange() - // instead. - virtual void FocusWillChange(View* focused_before, View* focused) OVERRIDE; + // Overridden from FocusChangeListener. + virtual void OnWillChangeFocus(View* focused_before, View* focused) OVERRIDE; + virtual void OnDidChangeFocus(View* focused_before, View* focused) OVERRIDE; protected: // Getters and setters of properties. internal::InputMethodDelegate* delegate() const { return delegate_; } Widget* widget() const { return widget_; } - View* focused_view() const { return focused_view_; } bool widget_focused() const { return widget_focused_; } + View* GetFocusedView() const; // Checks if the given View is focused. Returns true only if the View and // the Widget are both focused. @@ -83,22 +82,9 @@ class VIEWS_EXPORT InputMethodBase : public InputMethod, // Returns false if the current text input client doesn't support text input. bool GetCaretBoundsInWidget(gfx::Rect* rect) const; - // Called just before changing the focused view. Should be overridden by - // derived classes. The default implementation does nothing. - virtual void FocusedViewWillChange(); - - // Called just after changing the focused view. Should be overridden by - // derived classes. The default implementation does nothing. - // Note: It's called just after changing the value of |focused_view_|. As it's - // called inside FocusChangeListener's FocusWillChange() method, which is - // called by the FocusManager before actually changing the focus, the derived - // class should not rely on the actual focus state of the |focused_view_|. - virtual void FocusedViewDidChange(); - private: internal::InputMethodDelegate* delegate_; Widget* widget_; - View* focused_view_; // Indicates if the top-level widget is focused or not. bool widget_focused_; diff --git a/views/ime/input_method_gtk.cc b/views/ime/input_method_gtk.cc index 146cf6a..c50cb0e 100644 --- a/views/ime/input_method_gtk.cc +++ b/views/ime/input_method_gtk.cc @@ -8,6 +8,7 @@ #include <gdk/gdkkeysyms.h> #include <algorithm> +#include <string> #include "base/basictypes.h" #include "base/logging.h" @@ -134,16 +135,16 @@ void InputMethodGtk::DispatchKeyEvent(const KeyEvent& key) { handling_key_event_ = false; - const View* old_focused_view = focused_view(); + const View* old_focused_view = GetFocusedView(); if (key.type() == ui::ET_KEY_PRESSED && filtered) ProcessFilteredKeyPressEvent(key); // Ensure no focus change from processing the key event. - if (old_focused_view == focused_view()) { + if (old_focused_view == GetFocusedView()) { if (HasInputMethodResult()) ProcessInputMethodResult(key, filtered); // Ensure no focus change sending input method results to the focused View. - if (old_focused_view == focused_view()) { + if (old_focused_view == GetFocusedView()) { if (key.type() == ui::ET_KEY_PRESSED && !filtered) ProcessUnfilteredKeyPressEvent(key); else if (key.type() == ui::ET_KEY_RELEASED) @@ -194,17 +195,17 @@ bool InputMethodGtk::IsActive() { return true; } -void InputMethodGtk::FocusedViewWillChange() { +void InputMethodGtk::OnWillChangeFocus() { ConfirmCompositionText(); } -void InputMethodGtk::FocusedViewDidChange() { +void InputMethodGtk::OnDidChangeFocus() { UpdateContextFocusState(); // Force to update caret bounds, in case the View thinks that the caret // bounds has not changed. if (context_focused_) - OnCaretBoundsChanged(focused_view()); + OnCaretBoundsChanged(GetFocusedView()); } void InputMethodGtk::ConfirmCompositionText() { @@ -220,7 +221,7 @@ void InputMethodGtk::ResetContext() { return; DCHECK(widget_focused()); - DCHECK(focused_view()); + DCHECK(GetFocusedView()); DCHECK(!handling_key_event_); // To prevent any text from being committed when resetting the |context_|; @@ -282,12 +283,12 @@ void InputMethodGtk::ProcessFilteredKeyPressEvent(const KeyEvent& key) { } void InputMethodGtk::ProcessUnfilteredKeyPressEvent(const KeyEvent& key) { - const View* old_focused_view = focused_view(); + const View* old_focused_view = GetFocusedView(); DispatchKeyEventPostIME(key); // We shouldn't dispatch the character anymore if the key event caused focus // change. - if (old_focused_view != focused_view()) + if (old_focused_view != GetFocusedView()) return; // If a key event was not filtered by |context_| or |context_simple_|, then diff --git a/views/ime/input_method_gtk.h b/views/ime/input_method_gtk.h index 1fbdae5..a25a72a 100644 --- a/views/ime/input_method_gtk.h +++ b/views/ime/input_method_gtk.h @@ -38,8 +38,8 @@ class InputMethodGtk : public InputMethodBase { private: // Overridden from InputMethodBase: - virtual void FocusedViewWillChange() OVERRIDE; - virtual void FocusedViewDidChange() OVERRIDE; + virtual void OnWillChangeFocus() OVERRIDE; + virtual void OnDidChangeFocus() OVERRIDE; // Asks the client to confirm current composition text. void ConfirmCompositionText(); diff --git a/views/ime/input_method_ibus.cc b/views/ime/input_method_ibus.cc index 1eff716..a9fa1c3 100644 --- a/views/ime/input_method_ibus.cc +++ b/views/ime/input_method_ibus.cc @@ -5,15 +5,16 @@ #include "views/ime/input_method_ibus.h" #include <ibus.h> - -#include <cstring> -#include <set> - #if defined(TOUCH_UI) #include <X11/Xlib.h> #include <X11/Xutil.h> #endif +#include <algorithm> +#include <cstring> +#include <set> +#include <vector> + #include "base/command_line.h" #include "base/basictypes.h" #include "base/i18n/char_iterator.h" @@ -127,7 +128,7 @@ void ExtractCompositionTextFromIBusPreedit(IBusText* text, composition->selection = ui::Range(cursor_offset); if (text->attrs) { guint i = 0; - while(true) { + while (true) { IBusAttribute* attr = ibus_attr_list_get(text->attrs, i++); if (!attr) break; @@ -489,17 +490,17 @@ void InputMethodIBus::SetEnableInputMethodIBus(bool enabled) { inputmethod_ibus_enabled = enabled; } -void InputMethodIBus::FocusedViewWillChange() { +void InputMethodIBus::OnWillChangeFocus(View* focused_before, View* focused) { ConfirmCompositionText(); } -void InputMethodIBus::FocusedViewDidChange() { +void InputMethodIBus::OnDidChangeFocus(View* focused_before, View* focused) { UpdateContextFocusState(); // Force to update caret bounds, in case the View thinks that the caret // bounds has not changed. if (context_focused_) - OnCaretBoundsChanged(focused_view()); + OnCaretBoundsChanged(GetFocusedView()); } void InputMethodIBus::CreateContext() { @@ -607,7 +608,7 @@ void InputMethodIBus::ResetContext() { return; DCHECK(widget_focused()); - DCHECK(focused_view()); + DCHECK(GetFocusedView()); // Because ibus runs in asynchronous mode, the input method may still send us // results after sending out the reset request, so we use a flag to discard @@ -693,7 +694,7 @@ void InputMethodIBus::ProcessKeyEventPostIME(const KeyEvent& key, return; } - const View* old_focused_view = focused_view(); + const View* old_focused_view = GetFocusedView(); // Same reason as above DCHECK. DCHECK(old_focused_view); @@ -703,7 +704,7 @@ void InputMethodIBus::ProcessKeyEventPostIME(const KeyEvent& key, // In case the focus was changed by the key event. The |context_| should have // been reset when the focused view changed. - if (old_focused_view != focused_view()) + if (old_focused_view != GetFocusedView()) return; if (HasInputMethodResult()) @@ -711,7 +712,7 @@ void InputMethodIBus::ProcessKeyEventPostIME(const KeyEvent& key, // In case the focus was changed when sending input method results to the // focused View. - if (old_focused_view != focused_view()) + if (old_focused_view != GetFocusedView()) return; if (key.type() == ui::ET_KEY_PRESSED && !handled) @@ -731,12 +732,12 @@ void InputMethodIBus::ProcessFilteredKeyPressEvent(const KeyEvent& key) { void InputMethodIBus::ProcessUnfilteredKeyPressEvent(const KeyEvent& key, guint32 ibus_keyval) { - const View* old_focused_view = focused_view(); + const View* old_focused_view = GetFocusedView(); DispatchKeyEventPostIME(key); // We shouldn't dispatch the character anymore if the key event caused focus // change. - if (old_focused_view != focused_view()) + if (old_focused_view != GetFocusedView()) return; // Process compose and dead keys diff --git a/views/ime/input_method_ibus.h b/views/ime/input_method_ibus.h index 67832697..d07a457 100644 --- a/views/ime/input_method_ibus.h +++ b/views/ime/input_method_ibus.h @@ -63,8 +63,8 @@ class InputMethodIBus : public InputMethodBase { class PendingCreateICRequest; // Overridden from InputMethodBase: - virtual void FocusedViewWillChange() OVERRIDE; - virtual void FocusedViewDidChange() OVERRIDE; + virtual void OnWillChangeFocus(View* focused_before, View* focused) OVERRIDE; + virtual void OnDidChangeFocus(View* focused_before, View* focused) OVERRIDE; // Creates |context_| instance asynchronously. void CreateContext(); diff --git a/views/ime/input_method_win.cc b/views/ime/input_method_win.cc index cb27e588..12ae2f4 100644 --- a/views/ime/input_method_win.cc +++ b/views/ime/input_method_win.cc @@ -137,11 +137,11 @@ LRESULT InputMethodWin::OnImeMessages( return result; } -void InputMethodWin::FocusedViewWillChange() { +void InputMethodWin::OnWillChangeFocus(View* focused_before, View* focused) { ConfirmCompositionText(); } -void InputMethodWin::FocusedViewDidChange() { +void InputMethodWin::OnDidChangeFocus(View* focused_before, View* focused) { UpdateIMEState(); } diff --git a/views/ime/input_method_win.h b/views/ime/input_method_win.h index 8fdc90c..912a4c6 100644 --- a/views/ime/input_method_win.h +++ b/views/ime/input_method_win.h @@ -67,8 +67,8 @@ class InputMethodWin : public InputMethodBase { LRESULT OnReconvertString(RECONVERTSTRING *reconv); // Overridden from InputMethodBase. - virtual void FocusedViewWillChange() OVERRIDE; - virtual void FocusedViewDidChange() OVERRIDE; + virtual void OnWillChangeFocus(View* focused_before, View* focused) OVERRIDE; + virtual void OnDidChangeFocus(View* focused_before, View* focused) OVERRIDE; // A helper function to return the Widget's native window. HWND hwnd() const { return widget()->GetNativeView(); } diff --git a/views/ime/mock_input_method.cc b/views/ime/mock_input_method.cc index 5295585..07dca3ac 100644 --- a/views/ime/mock_input_method.cc +++ b/views/ime/mock_input_method.cc @@ -111,7 +111,7 @@ bool MockInputMethod::IsMock() const { return true; } -void MockInputMethod::FocusedViewWillChange() { +void MockInputMethod::OnWillChangeFocus(View* focused_before, View* focused) { TextInputClient* client = GetTextInputClient(); if (client && client->HasCompositionText()) client->ConfirmCompositionText(); diff --git a/views/ime/mock_input_method.h b/views/ime/mock_input_method.h index af4e0a5..01373eb 100644 --- a/views/ime/mock_input_method.h +++ b/views/ime/mock_input_method.h @@ -6,6 +6,8 @@ #define VIEWS_IME_MOCK_INPUT_METHOD_H_ #pragma once +#include <string> + #include "base/basictypes.h" #include "base/compiler_specific.h" #include "views/ime/input_method_base.h" @@ -48,7 +50,7 @@ class VIEWS_EXPORT MockInputMethod : public InputMethodBase { private: // Overridden from InputMethodBase. - virtual void FocusedViewWillChange() OVERRIDE; + virtual void OnWillChangeFocus(View* focused_before, View* focused) OVERRIDE; // Clears boolean states defined below. void ClearStates(); diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 03b7cfe..d1b032d 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -1408,7 +1408,7 @@ TEST_F(DefaultButtonTest, DialogDefaultButtonTest) { SimulatePressingEnterAndCheckDefaultButton(OK); // Simulate focusing another button, it should become the default button. - client_view_->FocusWillChange(ok_button_, test_dialog_->button1_); + client_view_->OnWillChangeFocus(ok_button_, test_dialog_->button1_); EXPECT_FALSE(ok_button_->is_default()); EXPECT_TRUE(test_dialog_->button1_->is_default()); // Simulate pressing enter, that should trigger button1. @@ -1416,29 +1416,29 @@ TEST_F(DefaultButtonTest, DialogDefaultButtonTest) { // Now select something that is not a button, the OK should become the default // button again. - client_view_->FocusWillChange(test_dialog_->button1_, - test_dialog_->checkbox_); + client_view_->OnWillChangeFocus(test_dialog_->button1_, + test_dialog_->checkbox_); EXPECT_TRUE(ok_button_->is_default()); EXPECT_FALSE(test_dialog_->button1_->is_default()); SimulatePressingEnterAndCheckDefaultButton(OK); // Select yet another button. - client_view_->FocusWillChange(test_dialog_->checkbox_, - test_dialog_->button2_); + client_view_->OnWillChangeFocus(test_dialog_->checkbox_, + test_dialog_->button2_); EXPECT_FALSE(ok_button_->is_default()); EXPECT_FALSE(test_dialog_->button1_->is_default()); EXPECT_TRUE(test_dialog_->button2_->is_default()); SimulatePressingEnterAndCheckDefaultButton(BUTTON2); // Focus nothing. - client_view_->FocusWillChange(test_dialog_->button2_, NULL); + client_view_->OnWillChangeFocus(test_dialog_->button2_, NULL); EXPECT_TRUE(ok_button_->is_default()); EXPECT_FALSE(test_dialog_->button1_->is_default()); EXPECT_FALSE(test_dialog_->button2_->is_default()); SimulatePressingEnterAndCheckDefaultButton(OK); // Focus the cancel button. - client_view_->FocusWillChange(NULL, cancel_button_); + client_view_->OnWillChangeFocus(NULL, cancel_button_); EXPECT_FALSE(ok_button_->is_default()); EXPECT_TRUE(cancel_button_->is_default()); EXPECT_FALSE(test_dialog_->button1_->is_default()); diff --git a/views/views.gyp b/views/views.gyp index d5b9d70..fb115d9 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -59,6 +59,8 @@ 'accelerator.h', 'accessibility/native_view_accessibility_win.cc', 'accessibility/native_view_accessibility_win.h', + 'accessible_pane_view.cc', + 'accessible_pane_view.h', 'animation/bounds_animator.cc', 'animation/bounds_animator.h', 'background.cc', @@ -575,6 +577,7 @@ '..', ], 'sources': [ + 'accessible_pane_view_unittest.cc', 'animation/bounds_animator_unittest.cc', 'bubble/bubble_delegate_unittest.cc', 'bubble/bubble_frame_view_unittest.cc', diff --git a/views/window/dialog_client_view.cc b/views/window/dialog_client_view.cc index 3dbea55..f0abe6f 100644 --- a/views/window/dialog_client_view.cc +++ b/views/window/dialog_client_view.cc @@ -190,8 +190,8 @@ void DialogClientView::SetDefaultButton(NativeTextButton* new_default_button) { } } -void DialogClientView::FocusWillChange(View* focused_before, - View* focused_now) { +void DialogClientView::OnWillChangeFocus(View* focused_before, + View* focused_now) { NativeTextButton* new_default_button = NULL; if (focused_now && focused_now->GetClassName() == NativeTextButton::kViewClassName) { @@ -209,6 +209,10 @@ void DialogClientView::FocusWillChange(View* focused_before, SetDefaultButton(new_default_button); } +void DialogClientView::OnDidChangeFocus(View* focused_before, + View* focused_now) { +} + // Changing dialog labels will change button widths. void DialogClientView::UpdateDialogButtons() { DialogDelegate* dd = GetDialogDelegate(); diff --git a/views/window/dialog_client_view.h b/views/window/dialog_client_view.h index 928ce57..379c8f0 100644 --- a/views/window/dialog_client_view.h +++ b/views/window/dialog_client_view.h @@ -76,8 +76,10 @@ class VIEWS_EXPORT DialogClientView : public ClientView, virtual const DialogClientView* AsDialogClientView() const OVERRIDE; // FocusChangeListener implementation: - virtual void FocusWillChange(View* focused_before, - View* focused_now) OVERRIDE; + virtual void OnWillChangeFocus(View* focused_before, + View* focused_now) OVERRIDE; + virtual void OnDidChangeFocus(View* focused_before, + View* focused_now) OVERRIDE; protected: // View overrides: |