diff options
author | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-14 13:33:23 +0000 |
---|---|---|
committer | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-14 13:33:23 +0000 |
commit | c5be11f4e5663736128f7c0b34af155155a27806 (patch) | |
tree | e46c093059f09005cec058df6202dc4b4035a7f0 /views | |
parent | 8bff0e34eb5f15a4f1210239a3aced0df9d5d317 (diff) | |
download | chromium_src-c5be11f4e5663736128f7c0b34af155155a27806.zip chromium_src-c5be11f4e5663736128f7c0b34af155155a27806.tar.gz chromium_src-c5be11f4e5663736128f7c0b34af155155a27806.tar.bz2 |
Move views::Accelerator to ui in order to use it from aura code.
This is the first preliminary change for the support of global keyboard shortcut.
BUG=97255
TEST=None
Review URL: http://codereview.chromium.org/8508055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
43 files changed, 137 insertions, 363 deletions
diff --git a/views/accelerator.cc b/views/accelerator.cc deleted file mode 100644 index 41a953d..0000000 --- a/views/accelerator.cc +++ /dev/null @@ -1,163 +0,0 @@ -// 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/accelerator.h" - -#if defined(OS_WIN) -#include <windows.h> -#elif defined(TOOLKIT_USES_GTK) -#include <gdk/gdk.h> -#endif - -#include "base/i18n/rtl.h" -#include "base/logging.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "grit/ui_strings.h" -#include "ui/base/l10n/l10n_util.h" - -namespace views { - -string16 Accelerator::GetShortcutText() const { - int string_id = 0; - switch(key_code_) { - case ui::VKEY_TAB: - string_id = IDS_APP_TAB_KEY; - break; - case ui::VKEY_RETURN: - string_id = IDS_APP_ENTER_KEY; - break; - case ui::VKEY_ESCAPE: - string_id = IDS_APP_ESC_KEY; - break; - case ui::VKEY_PRIOR: - string_id = IDS_APP_PAGEUP_KEY; - break; - case ui::VKEY_NEXT: - string_id = IDS_APP_PAGEDOWN_KEY; - break; - case ui::VKEY_END: - string_id = IDS_APP_END_KEY; - break; - case ui::VKEY_HOME: - string_id = IDS_APP_HOME_KEY; - break; - case ui::VKEY_INSERT: - string_id = IDS_APP_INSERT_KEY; - break; - case ui::VKEY_DELETE: - string_id = IDS_APP_DELETE_KEY; - break; - case ui::VKEY_LEFT: - string_id = IDS_APP_LEFT_ARROW_KEY; - break; - case ui::VKEY_RIGHT: - string_id = IDS_APP_RIGHT_ARROW_KEY; - break; - case ui::VKEY_BACK: - string_id = IDS_APP_BACKSPACE_KEY; - break; - case ui::VKEY_F1: - string_id = IDS_APP_F1_KEY; - break; - case ui::VKEY_F11: - string_id = IDS_APP_F11_KEY; - break; - default: - break; - } - - string16 shortcut; - if (!string_id) { -#if defined(OS_WIN) - // Our fallback is to try translate the key code to a regular character - // unless it is one of digits (VK_0 to VK_9). Some keyboard - // layouts have characters other than digits assigned in - // an unshifted mode (e.g. French AZERY layout has 'a with grave - // accent' for '0'). For display in the menu (e.g. Ctrl-0 for the - // default zoom level), we leave VK_[0-9] alone without translation. - wchar_t key; - if (key_code_ >= '0' && key_code_ <= '9') - key = key_code_; - else - key = LOWORD(::MapVirtualKeyW(key_code_, MAPVK_VK_TO_CHAR)); - shortcut += key; -#elif defined(TOOLKIT_USES_GTK) - const gchar* name = NULL; - switch (key_code_) { - case ui::VKEY_OEM_2: - name = static_cast<const gchar*>("/"); - break; - default: - name = gdk_keyval_name(gdk_keyval_to_lower(key_code_)); - break; - } - if (name) { - if (name[0] != 0 && name[1] == 0) - shortcut += static_cast<string16::value_type>(g_ascii_toupper(name[0])); - else - shortcut += UTF8ToUTF16(name); - } -#endif - } else { - shortcut = l10n_util::GetStringUTF16(string_id); - } - - // Checking whether the character used for the accelerator is alphanumeric. - // If it is not, then we need to adjust the string later on if the locale is - // right-to-left. See below for more information of why such adjustment is - // required. - string16 shortcut_rtl; - bool adjust_shortcut_for_rtl = false; - if (base::i18n::IsRTL() && shortcut.length() == 1 && - !IsAsciiAlpha(shortcut[0]) && !IsAsciiDigit(shortcut[0])) { - adjust_shortcut_for_rtl = true; - shortcut_rtl.assign(shortcut); - } - - if (IsShiftDown()) - shortcut = l10n_util::GetStringFUTF16(IDS_APP_SHIFT_MODIFIER, shortcut); - - // Note that we use 'else-if' in order to avoid using Ctrl+Alt as a shortcut. - // See http://blogs.msdn.com/oldnewthing/archive/2004/03/29/101121.aspx for - // more information. - if (IsCtrlDown()) - shortcut = l10n_util::GetStringFUTF16(IDS_APP_CONTROL_MODIFIER, shortcut); - else if (IsAltDown()) - shortcut = l10n_util::GetStringFUTF16(IDS_APP_ALT_MODIFIER, shortcut); - - // For some reason, menus in Windows ignore standard Unicode directionality - // marks (such as LRE, PDF, etc.). On RTL locales, we use RTL menus and - // therefore any text we draw for the menu items is drawn in an RTL context. - // Thus, the text "Ctrl++" (which we currently use for the Zoom In option) - // appears as "++Ctrl" in RTL because the Unicode BiDi algorithm puts - // punctuations on the left when the context is right-to-left. Shortcuts that - // do not end with a punctuation mark (such as "Ctrl+H" do not have this - // problem). - // - // The only way to solve this problem is to adjust the string if the locale - // is RTL so that it is drawn correnctly in an RTL context. Instead of - // returning "Ctrl++" in the above example, we return "++Ctrl". This will - // cause the text to appear as "Ctrl++" when Windows draws the string in an - // RTL context because the punctunation no longer appears at the end of the - // string. - // - // TODO(idana) bug# 1232732: this hack can be avoided if instead of using - // views::Menu we use views::MenuItemView because the latter is a View - // subclass and therefore it supports marking text as RTL or LTR using - // standard Unicode directionality marks. - if (adjust_shortcut_for_rtl) { - int key_length = static_cast<int>(shortcut_rtl.length()); - DCHECK_GT(key_length, 0); - shortcut_rtl.append(ASCIIToUTF16("+")); - - // Subtracting the size of the shortcut key and 1 for the '+' sign. - shortcut_rtl.append(shortcut, 0, shortcut.length() - key_length - 1); - shortcut.swap(shortcut_rtl); - } - - return shortcut; -} - -} // namespace views diff --git a/views/accelerator.h b/views/accelerator.h deleted file mode 100644 index 3dc2f0e9..0000000 --- a/views/accelerator.h +++ /dev/null @@ -1,73 +0,0 @@ -// 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. - -// This class describe a keyboard accelerator (or keyboard shortcut). -// Keyboard accelerators are registered with the FocusManager. -// It has a copy constructor and assignment operator so that it can be copied. -// It also defines the < operator so that it can be used as a key in a std::map. -// - -#ifndef VIEWS_ACCELERATOR_H_ -#define VIEWS_ACCELERATOR_H_ -#pragma once - -#include <string> - -#include "base/string16.h" -#include "ui/base/models/accelerator.h" -#include "views/events/event.h" -#include "views/views_export.h" - -namespace views { - -class VIEWS_EXPORT Accelerator : public ui::Accelerator { - public: - Accelerator() : ui::Accelerator() {} - - Accelerator(ui::KeyboardCode keycode, int modifiers) - : ui::Accelerator(keycode, modifiers) {} - - Accelerator(ui::KeyboardCode keycode, - bool shift_pressed, bool ctrl_pressed, bool alt_pressed) { - key_code_ = keycode; - modifiers_ = 0; - if (shift_pressed) - modifiers_ |= ui::EF_SHIFT_DOWN; - if (ctrl_pressed) - modifiers_ |= ui::EF_CONTROL_DOWN; - if (alt_pressed) - modifiers_ |= ui::EF_ALT_DOWN; - } - - virtual ~Accelerator() {} - - bool IsShiftDown() const { - return (modifiers_ & ui::EF_SHIFT_DOWN) == ui::EF_SHIFT_DOWN; - } - - bool IsCtrlDown() const { - return (modifiers_ & ui::EF_CONTROL_DOWN) == ui::EF_CONTROL_DOWN; - } - - bool IsAltDown() const { - return (modifiers_ & ui::EF_ALT_DOWN) == ui::EF_ALT_DOWN; - } - - // Returns a string with the localized shortcut if any. - string16 GetShortcutText() const; -}; - -// An interface that classes that want to register for keyboard accelerators -// should implement. -class VIEWS_EXPORT AcceleratorTarget { - public: - // This method should return true if the accelerator was processed. - virtual bool AcceleratorPressed(const Accelerator& accelerator) = 0; - - protected: - virtual ~AcceleratorTarget() {} -}; -} - -#endif // VIEWS_ACCELERATOR_H_ diff --git a/views/accessible_pane_view.cc b/views/accessible_pane_view.cc index 437bdba..2131991 100644 --- a/views/accessible_pane_view.cc +++ b/views/accessible_pane_view.cc @@ -115,7 +115,7 @@ views::FocusTraversable* AccessiblePaneView::GetPaneFocusTraversable() { } bool AccessiblePaneView::AcceleratorPressed( - const views::Accelerator& accelerator) { + const ui::Accelerator& accelerator) { const views::View* focused_view = focus_manager_->GetFocusedView(); if (!Contains(focused_view)) diff --git a/views/accessible_pane_view.h b/views/accessible_pane_view.h index e2ad84ba..a94c4af 100644 --- a/views/accessible_pane_view.h +++ b/views/accessible_pane_view.h @@ -9,6 +9,7 @@ #include "base/hash_tables.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "ui/base/models/accelerator.h" #include "views/focus/focus_manager.h" #include "views/view.h" @@ -41,7 +42,7 @@ class VIEWS_EXPORT AccessiblePaneView : public View, // Overridden from View: virtual FocusTraversable* GetPaneFocusTraversable() OVERRIDE; - virtual bool AcceleratorPressed(const Accelerator& accelerator) + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; virtual void SetVisible(bool flag) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; @@ -84,11 +85,11 @@ class VIEWS_EXPORT AccessiblePaneView : public View, scoped_ptr<FocusSearch> focus_search_; // Registered accelerators - Accelerator home_key_; - Accelerator end_key_; - Accelerator escape_key_; - Accelerator left_key_; - Accelerator right_key_; + ui::Accelerator home_key_; + ui::Accelerator end_key_; + ui::Accelerator escape_key_; + ui::Accelerator left_key_; + ui::Accelerator right_key_; DISALLOW_COPY_AND_ASSIGN(AccessiblePaneView); }; diff --git a/views/accessible_pane_view_unittest.cc b/views/accessible_pane_view_unittest.cc index 5d86ab89..1c54ba5 100644 --- a/views/accessible_pane_view_unittest.cc +++ b/views/accessible_pane_view_unittest.cc @@ -4,6 +4,7 @@ #include "views/accessible_pane_view.h" +#include "ui/base/models/accelerator.h" #include "views/controls/button/text_button.h" #include "views/layout/fill_layout.h" #include "views/test/views_test_base.h" @@ -29,11 +30,11 @@ class TestBarView : public AccessiblePaneView, 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_; } + const ui::Accelerator& home_key() const { return home_key_; } + const ui::Accelerator& end_key() const { return end_key_; } + const ui::Accelerator& escape_key() const { return escape_key_; } + const ui::Accelerator& left_key() const { return left_key_; } + const ui::Accelerator& right_key() const { return right_key_; } virtual View* GetDefaultFocusableChild() OVERRIDE; diff --git a/views/bubble/bubble_delegate.cc b/views/bubble/bubble_delegate.cc index 9f99747..f5efff1 100644 --- a/views/bubble/bubble_delegate.cc +++ b/views/bubble/bubble_delegate.cc @@ -83,7 +83,7 @@ BubbleDelegateView::BubbleDelegateView() border_widget_(NULL), use_focusless_(false) { set_background(views::Background::CreateSolidBackground(color_)); - AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); + AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, 0)); } BubbleDelegateView::BubbleDelegateView( @@ -100,7 +100,7 @@ BubbleDelegateView::BubbleDelegateView( border_widget_(NULL), use_focusless_(false) { set_background(views::Background::CreateSolidBackground(color_)); - AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); + AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, 0)); } BubbleDelegateView::~BubbleDelegateView() { @@ -215,7 +215,8 @@ void BubbleDelegateView::ResetFade() { GetWidget()->SetOpacity(original_opacity_); } -bool BubbleDelegateView::AcceleratorPressed(const Accelerator& accelerator) { +bool BubbleDelegateView::AcceleratorPressed( + const ui::Accelerator& accelerator) { if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) return false; if (fade_animation_.get()) diff --git a/views/bubble/bubble_delegate.h b/views/bubble/bubble_delegate.h index be02e44..55eb2e1 100644 --- a/views/bubble/bubble_delegate.h +++ b/views/bubble/bubble_delegate.h @@ -88,7 +88,7 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, protected: // View overrides: - virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; // Perform view initialization on the contents for bubble sizing. virtual void Init(); diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc index 05fac75..fc0c6b4 100644 --- a/views/controls/button/custom_button.cc +++ b/views/controls/button/custom_button.cc @@ -197,7 +197,7 @@ bool CustomButton::OnKeyReleased(const KeyEvent& event) { return true; } -bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) { +bool CustomButton::AcceleratorPressed(const ui::Accelerator& accelerator) { if (!View::IsEnabled()) return false; diff --git a/views/controls/button/custom_button.h b/views/controls/button/custom_button.h index 29e96d4..ae6a8bf 100644 --- a/views/controls/button/custom_button.h +++ b/views/controls/button/custom_button.h @@ -87,7 +87,7 @@ class VIEWS_EXPORT CustomButton : public Button, virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; virtual bool OnKeyPressed(const KeyEvent& event) OVERRIDE; virtual bool OnKeyReleased(const KeyEvent& event) OVERRIDE; - virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; virtual void ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) OVERRIDE; virtual void OnDragDone() OVERRIDE; diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc index 0b138cd..0c5b9cc 100644 --- a/views/controls/button/text_button.cc +++ b/views/controls/button/text_button.cc @@ -304,9 +304,9 @@ void TextButtonBase::SetIsDefault(bool is_default) { return; is_default_ = is_default; if (is_default_) - AddAccelerator(Accelerator(ui::VKEY_RETURN, false, false, false)); + AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, false, false, false)); else - RemoveAccelerator(Accelerator(ui::VKEY_RETURN, false, false, false)); + RemoveAccelerator(ui::Accelerator(ui::VKEY_RETURN, false, false, false)); SchedulePaint(); } diff --git a/views/controls/combobox/native_combobox_views.cc b/views/controls/combobox/native_combobox_views.cc index 724da9e..864b993 100644 --- a/views/controls/combobox/native_combobox_views.cc +++ b/views/controls/combobox/native_combobox_views.cc @@ -262,7 +262,7 @@ void NativeComboboxViews::ExecuteCommand(int id) { SchedulePaint(); } -bool NativeComboboxViews::GetAccelerator(int id, views::Accelerator* accel) { +bool NativeComboboxViews::GetAccelerator(int id, ui::Accelerator* accel) { return false; } diff --git a/views/controls/combobox/native_combobox_views.h b/views/controls/combobox/native_combobox_views.h index 5722e96..9a87259 100644 --- a/views/controls/combobox/native_combobox_views.h +++ b/views/controls/combobox/native_combobox_views.h @@ -58,7 +58,7 @@ class NativeComboboxViews : public views::View, virtual bool IsItemChecked(int id) const OVERRIDE; virtual bool IsCommandEnabled(int id) const OVERRIDE; virtual void ExecuteCommand(int id) OVERRIDE; - virtual bool GetAccelerator(int id, views::Accelerator* accelerator) OVERRIDE; + virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE; // class name of internal static const char kViewClassName[]; diff --git a/views/controls/menu/menu.h b/views/controls/menu/menu.h index 9397684..b6a9633 100644 --- a/views/controls/menu/menu.h +++ b/views/controls/menu/menu.h @@ -19,9 +19,11 @@ namespace gfx { class Point; } -namespace views { - +namespace ui { class Accelerator; +} + +namespace views { class VIEWS_EXPORT Menu { public: @@ -56,7 +58,7 @@ class VIEWS_EXPORT Menu { // The delegate needs to implement this function if it wants to display // the shortcut text next to each menu item. If there is an accelerator // for a given item id, the implementor must return it. - virtual bool GetAcceleratorInfo(int id, views::Accelerator* accel) { + virtual bool GetAcceleratorInfo(int id, ui::Accelerator* accel) { return false; } diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index df24a63..0983299 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -1066,7 +1066,7 @@ bool MenuController::SendAcceleratorToHotTrackedView() { if (!hot_view) return false; - Accelerator accelerator(ui::VKEY_RETURN, false, false, false); + ui::Accelerator accelerator(ui::VKEY_RETURN, false, false, false); hot_view->AcceleratorPressed(accelerator); hot_view->SetHotTracked(true); return true; diff --git a/views/controls/menu/menu_delegate.cc b/views/controls/menu/menu_delegate.cc index 6d5e8250..5ec4db4 100644 --- a/views/controls/menu/menu_delegate.cc +++ b/views/controls/menu/menu_delegate.cc @@ -26,7 +26,7 @@ string16 MenuDelegate::GetTooltipText(int id, return string16(); } -bool MenuDelegate::GetAccelerator(int id, Accelerator* accelerator) { +bool MenuDelegate::GetAccelerator(int id, ui::Accelerator* accelerator) { return false; } diff --git a/views/controls/menu/menu_delegate.h b/views/controls/menu/menu_delegate.h index fbae89a..dc29eb8 100644 --- a/views/controls/menu/menu_delegate.h +++ b/views/controls/menu/menu_delegate.h @@ -24,6 +24,12 @@ class Font; } // namespace gfx +namespace ui { + +class Accelerator; + +} // namespace ui + namespace views { class DropTargetEvent; @@ -73,7 +79,7 @@ class VIEWS_EXPORT MenuDelegate { // If there is an accelerator for the menu item with id |id| it is set in // |accelerator| and true is returned. - virtual bool GetAccelerator(int id, Accelerator* accelerator); + virtual bool GetAccelerator(int id, ui::Accelerator* accelerator); // Shows the context menu with the specified id. This is invoked when the // user does the appropriate gesture to show a context menu. The id diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index f1664eb..9d0d119 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -771,7 +771,7 @@ string16 MenuItemView::GetAcceleratorText() { if(!MenuConfig::instance().show_accelerators) return string16(); - Accelerator accelerator; + ui::Accelerator accelerator; return (GetDelegate() && GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? accelerator.GetShortcutText() : string16(); diff --git a/views/controls/menu/menu_model_adapter.cc b/views/controls/menu/menu_model_adapter.cc index 927768a..c232d2b 100644 --- a/views/controls/menu/menu_model_adapter.cc +++ b/views/controls/menu/menu_model_adapter.cc @@ -80,7 +80,7 @@ bool MenuModelAdapter::IsTriggerableEvent(MenuItemView* source, } bool MenuModelAdapter::GetAccelerator(int id, - views::Accelerator* accelerator) { + ui::Accelerator* accelerator) { ui::MenuModel* model = menu_model_; int index = 0; if (ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) diff --git a/views/controls/menu/menu_model_adapter.h b/views/controls/menu/menu_model_adapter.h index a85ad9f..8df4eef 100644 --- a/views/controls/menu/menu_model_adapter.h +++ b/views/controls/menu/menu_model_adapter.h @@ -46,7 +46,7 @@ class VIEWS_EXPORT MenuModelAdapter : public MenuDelegate { virtual bool IsTriggerableEvent(MenuItemView* source, const MouseEvent& e) OVERRIDE; virtual bool GetAccelerator(int id, - views::Accelerator* accelerator) OVERRIDE; + ui::Accelerator* accelerator) OVERRIDE; virtual string16 GetLabel(int id) const OVERRIDE; virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; virtual bool IsCommandEnabled(int id) const OVERRIDE; diff --git a/views/controls/menu/menu_win.cc b/views/controls/menu/menu_win.cc index 1e92bc5..f08ddd1 100644 --- a/views/controls/menu/menu_win.cc +++ b/views/controls/menu/menu_win.cc @@ -12,11 +12,11 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" +#include "ui/base/models/accelerator.h" #include "ui/base/win/window_impl.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/font.h" #include "ui/gfx/rect.h" -#include "views/accelerator.h" namespace views { @@ -442,7 +442,7 @@ void MenuWin::AddMenuItemInternal(int index, string16 actual_label(label.empty() ? delegate()->GetLabel(item_id) : label); // Find out if there is a shortcut we need to append to the label. - views::Accelerator accelerator(ui::VKEY_UNKNOWN, false, false, false); + ui::Accelerator accelerator(ui::VKEY_UNKNOWN, false, false, false); if (delegate() && delegate()->GetAcceleratorInfo(item_id, &accelerator)) { actual_label += L'\t'; actual_label += accelerator.GetShortcutText(); diff --git a/views/controls/menu/native_menu_gtk.cc b/views/controls/menu/native_menu_gtk.cc index d6b8394d..85b87b5 100644 --- a/views/controls/menu/native_menu_gtk.cc +++ b/views/controls/menu/native_menu_gtk.cc @@ -16,10 +16,10 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" #include "ui/base/keycodes/keyboard_codes.h" +#include "ui/base/models/accelerator.h" #include "ui/base/models/menu_model.h" #include "ui/gfx/font.h" #include "ui/gfx/gtk_util.h" -#include "views/accelerator.h" #include "views/controls/menu/menu_2.h" #include "views/controls/menu/menu_listener.h" #include "views/controls/menu/nested_dispatcher_gtk.h" @@ -420,7 +420,7 @@ GtkWidget* NativeMenuGtk::AddMenuItemAt(int index, G_CALLBACK(OnMenuMoveCurrentThunk), this); } - views::Accelerator accelerator(ui::VKEY_UNKNOWN, false, false, false); + ui::Accelerator accelerator(ui::VKEY_UNKNOWN, false, false, false); if (accel_group && model_->GetAcceleratorAt(index, &accelerator)) { int gdk_modifiers = 0; if (accelerator.IsShiftDown()) diff --git a/views/controls/menu/native_menu_views.cc b/views/controls/menu/native_menu_views.cc index 10d3ccf..ed8da66e 100644 --- a/views/controls/menu/native_menu_views.cc +++ b/views/controls/menu/native_menu_views.cc @@ -100,7 +100,7 @@ void NativeMenuViews::ExecuteCommand(int cmd) { model->ActivatedAt(index); } -bool NativeMenuViews::GetAccelerator(int id, views::Accelerator* accelerator) { +bool NativeMenuViews::GetAccelerator(int id, ui::Accelerator* accelerator) { int index; ui::MenuModel* model = model_; if (!ui::MenuModel::GetModelAndIndexForCommandId(id, &model, &index)) @@ -110,8 +110,8 @@ bool NativeMenuViews::GetAccelerator(int id, views::Accelerator* accelerator) { if (!model->GetAcceleratorAt(index, &menu_accelerator)) return false; - *accelerator = views::Accelerator(menu_accelerator.key_code(), - menu_accelerator.modifiers()); + *accelerator = ui::Accelerator(menu_accelerator.key_code(), + menu_accelerator.modifiers()); return true; } diff --git a/views/controls/menu/native_menu_views.h b/views/controls/menu/native_menu_views.h index 75e9100..33c8b92 100644 --- a/views/controls/menu/native_menu_views.h +++ b/views/controls/menu/native_menu_views.h @@ -43,7 +43,7 @@ class NativeMenuViews : public MenuWrapper, virtual bool IsItemChecked(int id) const OVERRIDE; virtual bool IsCommandEnabled(int id) const OVERRIDE; virtual void ExecuteCommand(int id) OVERRIDE; - virtual bool GetAccelerator(int id, views::Accelerator* accelerator) OVERRIDE; + virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE; private: void AddMenuItemsFromModel(MenuItemView* parent, ui::MenuModel* model); diff --git a/views/controls/menu/native_menu_win.cc b/views/controls/menu/native_menu_win.cc index 99094ae..1b6e738 100644 --- a/views/controls/menu/native_menu_win.cc +++ b/views/controls/menu/native_menu_win.cc @@ -16,12 +16,12 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" +#include "ui/base/models/accelerator.h" #include "ui/base/win/hwnd_util.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/font.h" #include "ui/gfx/native_theme.h" #include "ui/gfx/rect.h" -#include "views/accelerator.h" #include "views/controls/menu/menu_2.h" #include "views/controls/menu/menu_config.h" #include "views/controls/menu/menu_listener.h" @@ -684,7 +684,7 @@ void NativeMenuWin::UpdateMenuItemInfoForString(MENUITEMINFO* mii, ReplaceSubstringsAfterOffset(&formatted, 0, L"\t", L" "); if (type != ui::MenuModel::TYPE_SUBMENU) { // Add accelerator details to the label if provided. - views::Accelerator accelerator(ui::VKEY_UNKNOWN, false, false, false); + ui::Accelerator accelerator(ui::VKEY_UNKNOWN, false, false, false); if (model_->GetAcceleratorAt(model_index, &accelerator)) { formatted += L"\t"; formatted += accelerator.GetShortcutText(); diff --git a/views/controls/message_box_view.cc b/views/controls/message_box_view.cc index 8216f29..ba71a2a 100644 --- a/views/controls/message_box_view.cc +++ b/views/controls/message_box_view.cc @@ -102,8 +102,7 @@ void MessageBoxView::ViewHierarchyChanged(bool is_add, } } -bool MessageBoxView::AcceleratorPressed( - const Accelerator& accelerator) { +bool MessageBoxView::AcceleratorPressed(const ui::Accelerator& accelerator) { // We only accepts Ctrl-C. DCHECK(accelerator.key_code() == 'C' && accelerator.IsCtrlDown()); diff --git a/views/controls/message_box_view.h b/views/controls/message_box_view.h index 453f29a..5416b4b 100644 --- a/views/controls/message_box_view.h +++ b/views/controls/message_box_view.h @@ -65,8 +65,7 @@ class VIEWS_EXPORT MessageBoxView : public View { views::View* parent, views::View* child) OVERRIDE; // Handles Ctrl-C and writes the message in the system clipboard. - virtual bool AcceleratorPressed( - const views::Accelerator& accelerator) OVERRIDE; + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; private: // Sets up the layout manager and initializes the prompt field. This should diff --git a/views/controls/tabbed_pane/tabbed_pane.cc b/views/controls/tabbed_pane/tabbed_pane.cc index d17a3f7..72ff0ed 100644 --- a/views/controls/tabbed_pane/tabbed_pane.cc +++ b/views/controls/tabbed_pane/tabbed_pane.cc @@ -71,9 +71,9 @@ gfx::Size TabbedPane::GetPreferredSize() { void TabbedPane::LoadAccelerators() { // Ctrl+Shift+Tab - AddAccelerator(views::Accelerator(ui::VKEY_TAB, true, true, false)); + AddAccelerator(ui::Accelerator(ui::VKEY_TAB, true, true, false)); // Ctrl+Tab - AddAccelerator(views::Accelerator(ui::VKEY_TAB, false, true, false)); + AddAccelerator(ui::Accelerator(ui::VKEY_TAB, false, true, false)); } void TabbedPane::Layout() { @@ -91,7 +91,7 @@ void TabbedPane::ViewHierarchyChanged(bool is_add, View* parent, View* child) { } } -bool TabbedPane::AcceleratorPressed(const views::Accelerator& accelerator) { +bool TabbedPane::AcceleratorPressed(const ui::Accelerator& accelerator) { // We only accept Ctrl+Tab keyboard events. DCHECK(accelerator.key_code() == ui::VKEY_TAB && accelerator.IsCtrlDown()); diff --git a/views/controls/tabbed_pane/tabbed_pane.h b/views/controls/tabbed_pane/tabbed_pane.h index d9d51df..6161d76 100644 --- a/views/controls/tabbed_pane/tabbed_pane.h +++ b/views/controls/tabbed_pane/tabbed_pane.h @@ -85,8 +85,7 @@ class VIEWS_EXPORT TabbedPane : public View { View* parent, View* child) OVERRIDE; // Handles Ctrl+Tab and Ctrl+Shift+Tab navigation of pages. - virtual bool AcceleratorPressed( - const views::Accelerator& accelerator) OVERRIDE; + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; virtual std::string GetClassName() const OVERRIDE; virtual void OnFocus() OVERRIDE; virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index f1c2dc0..0b0c6f6 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -416,13 +416,13 @@ bool NativeTextfieldWin::GetAcceleratorForCommandId(int command_id, // anywhere so we need to check for them explicitly here. switch (command_id) { case IDS_APP_CUT: - *accelerator = views::Accelerator(ui::VKEY_X, false, true, false); + *accelerator = ui::Accelerator(ui::VKEY_X, false, true, false); return true; case IDS_APP_COPY: - *accelerator = views::Accelerator(ui::VKEY_C, false, true, false); + *accelerator = ui::Accelerator(ui::VKEY_C, false, true, false); return true; case IDS_APP_PASTE: - *accelerator = views::Accelerator(ui::VKEY_V, false, true, false); + *accelerator = ui::Accelerator(ui::VKEY_V, false, true, false); return true; } return container_view_->GetWidget()->GetAccelerator(command_id, accelerator); diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc index 80313ed..c0a4c657 100644 --- a/views/controls/tree/tree_view.cc +++ b/views/controls/tree/tree_view.cc @@ -15,6 +15,7 @@ #include "ui/base/keycodes/keyboard_code_conversion_win.h" #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util_win.h" +#include "ui/base/models/accelerator.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/win/hwnd_util.h" #include "ui/gfx/canvas_skia.h" @@ -474,10 +475,10 @@ bool TreeView::OnKeyDown(ui::KeyboardCode virtual_key_code) { } else if (virtual_key_code == ui::VKEY_RETURN && !process_enter_) { Widget* widget = GetWidget(); DCHECK(widget); - Accelerator accelerator(Accelerator(virtual_key_code, - base::win::IsShiftPressed(), - base::win::IsCtrlPressed(), - base::win::IsAltPressed())); + ui::Accelerator accelerator(ui::Accelerator(virtual_key_code, + base::win::IsShiftPressed(), + base::win::IsCtrlPressed(), + base::win::IsAltPressed())); GetFocusManager()->ProcessAccelerator(accelerator); return true; } diff --git a/views/focus/accelerator_handler_gtk.cc b/views/focus/accelerator_handler_gtk.cc index e795d06..fab3b86 100644 --- a/views/focus/accelerator_handler_gtk.cc +++ b/views/focus/accelerator_handler_gtk.cc @@ -6,7 +6,6 @@ #include <gtk/gtk.h> -#include "views/accelerator.h" #include "views/focus/focus_manager.h" namespace views { diff --git a/views/focus/accelerator_handler_gtk_unittest.cc b/views/focus/accelerator_handler_gtk_unittest.cc index bedd6d5..098325d 100644 --- a/views/focus/accelerator_handler_gtk_unittest.cc +++ b/views/focus/accelerator_handler_gtk_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 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. @@ -6,6 +6,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/rect.h" +#include "ui/base/models/accelerator.h" #include "views/focus/accelerator_handler.h" #include "views/focus/focus_manager.h" #include "views/view.h" @@ -17,7 +18,7 @@ namespace views { class AcceleratorHandlerGtkTest : public testing::Test, public WidgetDelegate, - public AcceleratorTarget { + public ui::AcceleratorTarget { public: AcceleratorHandlerGtkTest() : kMenuAccelerator(ui::VKEY_MENU, false, false, false), @@ -58,7 +59,7 @@ class AcceleratorHandlerGtkTest } // AcceleratorTarget implementation. - virtual bool AcceleratorPressed(const Accelerator& accelerator) { + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { if (accelerator == kMenuAccelerator) menu_pressed_ = true; else if (accelerator == kHomepageAccelerator) @@ -87,8 +88,8 @@ class AcceleratorHandlerGtkTest bool home_pressed_; private: - Accelerator kMenuAccelerator; - Accelerator kHomepageAccelerator; + ui::Accelerator kMenuAccelerator; + ui::Accelerator kHomepageAccelerator; Widget* window_; View* content_view_; MessageLoopForUI message_loop_; diff --git a/views/focus/accelerator_handler_touch.cc b/views/focus/accelerator_handler_touch.cc index 99dd049..6b452bd 100644 --- a/views/focus/accelerator_handler_touch.cc +++ b/views/focus/accelerator_handler_touch.cc @@ -9,7 +9,6 @@ #include <X11/extensions/XInput2.h> #include "ui/base/touch/touch_factory.h" -#include "views/accelerator.h" #include "views/events/event.h" #include "views/focus/focus_manager.h" #include "views/ime/input_method.h" diff --git a/views/focus/accelerator_handler_wayland.cc b/views/focus/accelerator_handler_wayland.cc index 1039570..6a88b03 100644 --- a/views/focus/accelerator_handler_wayland.cc +++ b/views/focus/accelerator_handler_wayland.cc @@ -4,7 +4,6 @@ #include "views/focus/accelerator_handler.h" -#include "views/accelerator.h" #include "views/focus/focus_manager.h" namespace views { diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc index 9697597..5ebcb71 100644 --- a/views/focus/focus_manager.cc +++ b/views/focus/focus_manager.cc @@ -10,7 +10,7 @@ #include "base/logging.h" #include "build/build_config.h" #include "ui/base/keycodes/keyboard_codes.h" -#include "views/accelerator.h" +#include "ui/base/models/accelerator.h" #include "views/focus/focus_search.h" #include "views/focus/view_storage.h" #include "views/focus/widget_focus_manager.h" @@ -86,10 +86,10 @@ bool FocusManager::OnKeyEvent(const KeyEvent& event) { // Process keyboard accelerators. // If the key combination matches an accelerator, the accelerator is // triggered, otherwise the key event is processed as usual. - Accelerator accelerator(event.key_code(), - event.IsShiftDown(), - event.IsControlDown(), - event.IsAltDown()); + ui::Accelerator accelerator(event.key_code(), + event.IsShiftDown(), + event.IsControlDown(), + event.IsAltDown()); if (ProcessAccelerator(accelerator)) { // If a shortcut was activated for this keydown message, do not propagate // the event further. @@ -359,16 +359,16 @@ View* FocusManager::FindFocusableView(FocusTraversable* focus_traversable, } void FocusManager::RegisterAccelerator( - const Accelerator& accelerator, - AcceleratorTarget* target) { + const ui::Accelerator& accelerator, + ui::AcceleratorTarget* target) { AcceleratorTargetList& targets = accelerators_[accelerator]; DCHECK(std::find(targets.begin(), targets.end(), target) == targets.end()) << "Registering the same target multiple times"; targets.push_front(target); } -void FocusManager::UnregisterAccelerator(const Accelerator& accelerator, - AcceleratorTarget* target) { +void FocusManager::UnregisterAccelerator(const ui::Accelerator& accelerator, + ui::AcceleratorTarget* target) { AcceleratorMap::iterator map_iter = accelerators_.find(accelerator); if (map_iter == accelerators_.end()) { NOTREACHED() << "Unregistering non-existing accelerator"; @@ -386,7 +386,7 @@ void FocusManager::UnregisterAccelerator(const Accelerator& accelerator, targets->erase(target_iter); } -void FocusManager::UnregisterAccelerators(AcceleratorTarget* target) { +void FocusManager::UnregisterAccelerators(ui::AcceleratorTarget* target) { for (AcceleratorMap::iterator map_iter = accelerators_.begin(); map_iter != accelerators_.end(); ++map_iter) { AcceleratorTargetList* targets = &map_iter->second; @@ -394,7 +394,7 @@ void FocusManager::UnregisterAccelerators(AcceleratorTarget* target) { } } -bool FocusManager::ProcessAccelerator(const Accelerator& accelerator) { +bool FocusManager::ProcessAccelerator(const ui::Accelerator& accelerator) { AcceleratorMap::iterator map_iter = accelerators_.find(accelerator); if (map_iter != accelerators_.end()) { // We have to copy the target list here, because an AcceleratorPressed @@ -409,8 +409,8 @@ bool FocusManager::ProcessAccelerator(const Accelerator& accelerator) { return false; } -AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator( - const views::Accelerator& accelerator) const { +ui::AcceleratorTarget* FocusManager::GetCurrentTargetForAccelerator( + const ui::Accelerator& accelerator) const { AcceleratorMap::const_iterator map_iter = accelerators_.find(accelerator); if (map_iter == accelerators_.end() || map_iter->second.empty()) return NULL; diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h index 0fa5139..8ac84c5d 100644 --- a/views/focus/focus_manager.h +++ b/views/focus/focus_manager.h @@ -11,8 +11,10 @@ #include "base/basictypes.h" #include "base/observer_list.h" +#include "ui/base/models/accelerator.h" #include "ui/gfx/native_widget_types.h" -#include "views/accelerator.h" +#include "views/views_export.h" +#include "views/events/event.h" // The FocusManager class is used to handle focus traversal, store/restore // focused views and handle keyboard accelerators. @@ -187,15 +189,15 @@ class VIEWS_EXPORT FocusManager { // - the enter key // - any F key (F1, F2, F3 ...) // - any browser specific keys (as available on special keyboards) - void RegisterAccelerator(const Accelerator& accelerator, - AcceleratorTarget* target); + void RegisterAccelerator(const ui::Accelerator& accelerator, + ui::AcceleratorTarget* target); // Unregister the specified keyboard accelerator for the specified target. - void UnregisterAccelerator(const Accelerator& accelerator, - AcceleratorTarget* target); + void UnregisterAccelerator(const ui::Accelerator& accelerator, + ui::AcceleratorTarget* target); // Unregister all keyboard accelerator for the specified target. - void UnregisterAccelerators(AcceleratorTarget* target); + void UnregisterAccelerators(ui::AcceleratorTarget* target); // Activate the target associated with the specified accelerator. // First, AcceleratorPressed handler of the most recently registered target @@ -203,7 +205,7 @@ class VIEWS_EXPORT FocusManager { // this method immediately returns. If not, we do the same thing on the next // target, and so on. // Returns true if an accelerator was activated. - bool ProcessAccelerator(const Accelerator& accelerator); + bool ProcessAccelerator(const ui::Accelerator& accelerator); // Called by a RootView when a view within its hierarchy is removed // from its parent. This will only be called by a RootView in a @@ -219,8 +221,8 @@ class VIEWS_EXPORT FocusManager { // Returns the AcceleratorTarget that should be activated for the specified // keyboard accelerator, or NULL if no view is registered for that keyboard // accelerator. - AcceleratorTarget* GetCurrentTargetForAccelerator( - const Accelerator& accelertor) const; + ui::AcceleratorTarget* GetCurrentTargetForAccelerator( + const ui::Accelerator& accelertor) const; // Sets the focus to the specified native view. virtual void FocusNativeView(gfx::NativeView native_view); @@ -259,8 +261,8 @@ class VIEWS_EXPORT FocusManager { FocusChangeReason focus_change_reason_; // The accelerators and associated targets. - typedef std::list<AcceleratorTarget*> AcceleratorTargetList; - typedef std::map<Accelerator, AcceleratorTargetList> AcceleratorMap; + typedef std::list<ui::AcceleratorTarget*> AcceleratorTargetList; + typedef std::map<ui::Accelerator, AcceleratorTargetList> AcceleratorMap; AcceleratorMap accelerators_; // The list of registered FocusChange listeners. diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc index 574182d..6485405 100644 --- a/views/focus/focus_manager_unittest.cc +++ b/views/focus/focus_manager_unittest.cc @@ -8,6 +8,7 @@ #include "base/utf_string_conversions.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/base/keycodes/keyboard_codes.h" +#include "ui/base/models/accelerator.h" #include "ui/base/models/combobox_model.h" #include "ui/gfx/rect.h" #include "views/background.h" @@ -1291,12 +1292,12 @@ TEST_F(FocusTraversalTest, PaneTraversal) { } // Counts accelerator calls. -class TestAcceleratorTarget : public AcceleratorTarget { +class TestAcceleratorTarget : public ui::AcceleratorTarget { public: explicit TestAcceleratorTarget(bool process_accelerator) : accelerator_count_(0), process_accelerator_(process_accelerator) {} - virtual bool AcceleratorPressed(const Accelerator& accelerator) { + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { ++accelerator_count_; return process_accelerator_; } @@ -1312,8 +1313,8 @@ class TestAcceleratorTarget : public AcceleratorTarget { TEST_F(FocusManagerTest, CallsNormalAcceleratorTarget) { FocusManager* focus_manager = GetFocusManager(); - Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); - Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); + ui::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); + ui::Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); TestAcceleratorTarget return_target(true); TestAcceleratorTarget escape_target(true); @@ -1403,16 +1404,16 @@ TEST_F(FocusManagerTest, CallsNormalAcceleratorTarget) { } // Unregisters itself when its accelerator is invoked. -class SelfUnregisteringAcceleratorTarget : public AcceleratorTarget { +class SelfUnregisteringAcceleratorTarget : public ui::AcceleratorTarget { public: - SelfUnregisteringAcceleratorTarget(Accelerator accelerator, + SelfUnregisteringAcceleratorTarget(ui::Accelerator accelerator, FocusManager* focus_manager) : accelerator_(accelerator), focus_manager_(focus_manager), accelerator_count_(0) { } - virtual bool AcceleratorPressed(const Accelerator& accelerator) { + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { ++accelerator_count_; focus_manager_->UnregisterAccelerator(accelerator, this); return true; @@ -1421,7 +1422,7 @@ class SelfUnregisteringAcceleratorTarget : public AcceleratorTarget { int accelerator_count() const { return accelerator_count_; } private: - Accelerator accelerator_; + ui::Accelerator accelerator_; FocusManager* focus_manager_; int accelerator_count_; @@ -1430,7 +1431,7 @@ class SelfUnregisteringAcceleratorTarget : public AcceleratorTarget { TEST_F(FocusManagerTest, CallsSelfDeletingAcceleratorTarget) { FocusManager* focus_manager = GetFocusManager(); - Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); + ui::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); SelfUnregisteringAcceleratorTarget target(return_accelerator, focus_manager); EXPECT_EQ(target.accelerator_count(), 0); EXPECT_EQ(NULL, @@ -1467,7 +1468,7 @@ class MessageTrackingView : public View { return true; } - virtual bool AcceleratorPressed(const Accelerator& accelerator) { + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { accelerator_pressed_ = true; return true; } @@ -1506,8 +1507,8 @@ class MessageTrackingView : public View { TEST_F(FocusManagerTest, IgnoreKeyupForAccelerators) { FocusManager* focus_manager = GetFocusManager(); MessageTrackingView* mtv = new MessageTrackingView(); - mtv->AddAccelerator(Accelerator(ui::VKEY_0, false, false, false)); - mtv->AddAccelerator(Accelerator(ui::VKEY_1, false, false, false)); + mtv->AddAccelerator(ui::Accelerator(ui::VKEY_0, false, false, false)); + mtv->AddAccelerator(ui::Accelerator(ui::VKEY_1, false, false, false)); content_view_->AddChildView(mtv); focus_manager->SetFocusedView(mtv); diff --git a/views/view.cc b/views/view.cc index 698caba..1539cc5 100644 --- a/views/view.cc +++ b/views/view.cc @@ -804,9 +804,9 @@ InputMethod* View::GetInputMethod() { // Accelerators ---------------------------------------------------------------- -void View::AddAccelerator(const Accelerator& accelerator) { +void View::AddAccelerator(const ui::Accelerator& accelerator) { if (!accelerators_.get()) - accelerators_.reset(new std::vector<Accelerator>()); + accelerators_.reset(new std::vector<ui::Accelerator>()); DCHECK(std::find(accelerators_->begin(), accelerators_->end(), accelerator) == accelerators_->end()) @@ -816,13 +816,13 @@ void View::AddAccelerator(const Accelerator& accelerator) { RegisterPendingAccelerators(); } -void View::RemoveAccelerator(const Accelerator& accelerator) { +void View::RemoveAccelerator(const ui::Accelerator& accelerator) { if (!accelerators_.get()) { NOTREACHED() << "Removing non-existing accelerator"; return; } - std::vector<Accelerator>::iterator i( + std::vector<ui::Accelerator>::iterator i( std::find(accelerators_->begin(), accelerators_->end(), accelerator)); if (i == accelerators_->end()) { NOTREACHED() << "Removing non-existing accelerator"; @@ -848,7 +848,7 @@ void View::ResetAccelerators() { UnregisterAccelerators(false); } -bool View::AcceleratorPressed(const Accelerator& accelerator) { +bool View::AcceleratorPressed(const ui::Accelerator& accelerator) { return false; } @@ -1961,7 +1961,7 @@ void View::RegisterPendingAccelerators() { // Only register accelerators if we are visible. if (!IsVisibleInRootView() || !GetWidget()->IsVisible()) return; - for (std::vector<Accelerator>::const_iterator i( + for (std::vector<ui::Accelerator>::const_iterator i( accelerators_->begin() + registered_accelerator_count_); i != accelerators_->end(); ++i) { accelerator_focus_manager_->RegisterAccelerator(*i, this); diff --git a/views/view.h b/views/view.h index 222833a..0b0ae89 100644 --- a/views/view.h +++ b/views/view.h @@ -18,12 +18,13 @@ #include "base/memory/scoped_ptr.h" #include "build/build_config.h" #include "ui/base/dragdrop/os_exchange_data.h" +#include "ui/base/models/accelerator.h" #include "ui/gfx/compositor/layer_delegate.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" -#include "views/accelerator.h" #include "views/background.h" #include "views/border.h" +#include "views/events/event.h" #if defined(OS_WIN) #include "base/win/scoped_comptr.h" @@ -98,7 +99,7 @@ class RootView; // ///////////////////////////////////////////////////////////////////////////// class VIEWS_EXPORT View : public ui::LayerDelegate, - public AcceleratorTarget { + public ui::AcceleratorTarget { public: typedef std::vector<View*> Views; @@ -636,16 +637,16 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // accelerator key combination, the AcceleratorPressed method is invoked. // Note that you can set multiple accelerators for a view by invoking this // method several times. - virtual void AddAccelerator(const Accelerator& accelerator); + virtual void AddAccelerator(const ui::Accelerator& accelerator); // Removes the specified accelerator for this view. - virtual void RemoveAccelerator(const Accelerator& accelerator); + virtual void RemoveAccelerator(const ui::Accelerator& accelerator); // Removes all the keyboard accelerators for this view. virtual void ResetAccelerators(); // Overridden from AcceleratorTarget: - virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; // Focus --------------------------------------------------------------------- @@ -1410,7 +1411,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // The list of accelerators. List elements in the range // [0, registered_accelerator_count_) are already registered to FocusManager, // and the rest are not yet. - scoped_ptr<std::vector<Accelerator> > accelerators_; + scoped_ptr<std::vector<ui::Accelerator> > accelerators_; size_t registered_accelerator_count_; // Focus --------------------------------------------------------------------- diff --git a/views/view_unittest.cc b/views/view_unittest.cc index d1b032d..545c1ab 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -12,6 +12,7 @@ #include "ui/base/clipboard/clipboard.h" #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/models/simple_menu_model.h" +#include "ui/base/models/accelerator.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/layer.h" @@ -215,7 +216,7 @@ class TestView : public View { virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; virtual void Paint(gfx::Canvas* canvas) OVERRIDE; virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; - virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; + virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; // OnBoundsChanged. bool did_change_bounds_; @@ -237,7 +238,7 @@ class TestView : public View { SkRect last_clip_; // Accelerators. - std::map<Accelerator, int> accelerator_count_map_; + std::map<ui::Accelerator, int> accelerator_count_map_; }; // Mock instance of the GestureManager for testing. @@ -963,7 +964,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) { //////////////////////////////////////////////////////////////////////////////// // Accelerators //////////////////////////////////////////////////////////////////////////////// -bool TestView::AcceleratorPressed(const Accelerator& accelerator) { +bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) { accelerator_count_map_[accelerator]++; return true; } @@ -971,7 +972,7 @@ bool TestView::AcceleratorPressed(const Accelerator& accelerator) { #if defined(OS_WIN) && !defined(USE_AURA) TEST_F(ViewTest, ActivateAccelerator) { // Register a keyboard accelerator before the view is added to a window. - Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); + ui::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); TestView* view = new TestView(); view->Reset(); view->AddAccelerator(return_accelerator); @@ -996,7 +997,7 @@ TEST_F(ViewTest, ActivateAccelerator) { EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); // Hit the escape key. Nothing should happen. - Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); + ui::Accelerator escape_accelerator(ui::VKEY_ESCAPE, false, false, false); EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0); @@ -1037,7 +1038,7 @@ TEST_F(ViewTest, ActivateAccelerator) { #if defined(OS_WIN) && !defined(USE_AURA) TEST_F(ViewTest, HiddenViewWithAccelerator) { - Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); + ui::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); TestView* view = new TestView(); view->Reset(); view->AddAccelerator(return_accelerator); @@ -1069,7 +1070,7 @@ TEST_F(ViewTest, HiddenViewWithAccelerator) { #if defined(OS_WIN) && !defined(USE_AURA) TEST_F(ViewTest, ViewInHiddenWidgetWithAccelerator) { - Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); + ui::Accelerator return_accelerator(ui::VKEY_RETURN, false, false, false); TestView* view = new TestView(); view->Reset(); view->AddAccelerator(return_accelerator); diff --git a/views/views.gyp b/views/views.gyp index 148904f9..30c4dc7 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -55,8 +55,6 @@ ], 'sources': [ # All .cc, .h under views, except unittests - 'accelerator.cc', - 'accelerator.h', 'accessibility/native_view_accessibility_win.cc', 'accessibility/native_view_accessibility_win.h', 'accessible_pane_view.cc', diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc index 88a2f6e..240c2ad 100644 --- a/views/widget/native_widget_gtk.cc +++ b/views/widget/native_widget_gtk.cc @@ -614,7 +614,7 @@ bool NativeWidgetGtk::HandleKeyboardEvent(const KeyEvent& key) { (key.flags() & ~ui::EF_ALT_DOWN) == 0) { // Trigger VKEY_MENU when only this key is pressed and released, and both // press and release events are not handled by others. - Accelerator accelerator(ui::VKEY_MENU, false, false, false); + ui::Accelerator accelerator(ui::VKEY_MENU, false, false, false); handled = GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator); } diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc index e31196e..8b98ffa 100644 --- a/views/widget/native_widget_win.cc +++ b/views/widget/native_widget_win.cc @@ -1879,10 +1879,10 @@ void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) { if ((notification_code & sc_mask) == SC_KEYMENU && click.x == 0) { // Retrieve the status of shift and control keys to prevent consuming // shift+alt keys, which are used by Windows to change input languages. - Accelerator accelerator(ui::KeyboardCodeForWindowsKeyCode(VK_MENU), - !!(GetKeyState(VK_SHIFT) & 0x8000), - !!(GetKeyState(VK_CONTROL) & 0x8000), - false); + ui::Accelerator accelerator(ui::KeyboardCodeForWindowsKeyCode(VK_MENU), + !!(GetKeyState(VK_SHIFT) & 0x8000), + !!(GetKeyState(VK_CONTROL) & 0x8000), + false); GetWidget()->GetFocusManager()->ProcessAccelerator(accelerator); return; } |