Commit ada9c0c0 authored by oshima@chromium.org's avatar oshima@chromium.org

Fix key navigation to cut/copy/paste zoom button on wrench menu

* Fix button class detection (added CustomButton::AsCustomButtton)
* Removed obsolete touch specific color scheme. Instead, use
 NativeTheme as that's what MenuItemView is using.

BUG=177228

Review URL: https://codereview.chromium.org/82113004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238241 0039d316-1c4b-4281-b951-d872f2087c98
parent 402253d1
...@@ -9,6 +9,13 @@ ...@@ -9,6 +9,13 @@
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/animation/throb_animation.h" #include "ui/gfx/animation/throb_animation.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/views/controls/button/blue_button.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/controls/button/text_button.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace views { namespace views {
...@@ -22,6 +29,27 @@ const char CustomButton::kViewClassName[] = "CustomButton"; ...@@ -22,6 +29,27 @@ const char CustomButton::kViewClassName[] = "CustomButton";
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// CustomButton, public: // CustomButton, public:
// static
const CustomButton* CustomButton::AsCustomButton(const views::View* view) {
return AsCustomButton(const_cast<views::View*>(view));
}
CustomButton* CustomButton::AsCustomButton(views::View* view) {
if (view) {
const char* classname = view->GetClassName();
if (!strcmp(classname, Checkbox::kViewClassName) ||
!strcmp(classname, CustomButton::kViewClassName) ||
!strcmp(classname, ImageButton::kViewClassName) ||
!strcmp(classname, LabelButton::kViewClassName) ||
!strcmp(classname, RadioButton::kViewClassName) ||
!strcmp(classname, MenuButton::kViewClassName) ||
!strcmp(classname, TextButton::kViewClassName)) {
return static_cast<CustomButton*>(view);
}
}
return NULL;
}
CustomButton::~CustomButton() { CustomButton::~CustomButton() {
} }
......
...@@ -29,6 +29,9 @@ class VIEWS_EXPORT CustomButton : public Button, ...@@ -29,6 +29,9 @@ class VIEWS_EXPORT CustomButton : public Button,
// The menu button's class name. // The menu button's class name.
static const char kViewClassName[]; static const char kViewClassName[];
static const CustomButton* AsCustomButton(const views::View* view);
static CustomButton* AsCustomButton(views::View* view);
virtual ~CustomButton(); virtual ~CustomButton();
// Get/sets the current display state of the button. // Get/sets the current display state of the button.
......
...@@ -7,6 +7,13 @@ ...@@ -7,6 +7,13 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/menu_button.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/controls/button/text_button.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
#if defined(USE_AURA) #if defined(USE_AURA)
...@@ -143,4 +150,34 @@ TEST_F(CustomButtonTest, GestureEventsSetState) { ...@@ -143,4 +150,34 @@ TEST_F(CustomButtonTest, GestureEventsSetState) {
#endif // USE_AURA #endif // USE_AURA
// Make sure all subclasses of CustomButton are correctly recognized
// as CustomButton.
TEST_F(CustomButtonTest, AsCustomButton) {
string16 text;
TextButton text_button(NULL, text);
EXPECT_TRUE(CustomButton::AsCustomButton(&text_button));
ImageButton image_button(NULL);
EXPECT_TRUE(CustomButton::AsCustomButton(&image_button));
Checkbox checkbox(text);
EXPECT_TRUE(CustomButton::AsCustomButton(&checkbox));
RadioButton radio_button(text, 0);
EXPECT_TRUE(CustomButton::AsCustomButton(&radio_button));
MenuButton menu_button(NULL, text, NULL, false);
EXPECT_TRUE(CustomButton::AsCustomButton(&menu_button));
Label label;
EXPECT_FALSE(CustomButton::AsCustomButton(&label));
Link link(text);
EXPECT_FALSE(CustomButton::AsCustomButton(&link));
Textfield textfield(Textfield::STYLE_DEFAULT);
EXPECT_FALSE(CustomButton::AsCustomButton(&textfield));
}
} // namespace views } // namespace views
...@@ -103,18 +103,17 @@ bool TitleMatchesMnemonic(MenuItemView* menu, char16 key) { ...@@ -103,18 +103,17 @@ bool TitleMatchesMnemonic(MenuItemView* menu, char16 key) {
} // namespace } // namespace
// Returns the first descendant of |view| that is hot tracked. // Returns the first descendant of |view| that is hot tracked.
static View* GetFirstHotTrackedView(View* view) { static CustomButton* GetFirstHotTrackedView(View* view) {
if (!view) if (!view)
return NULL; return NULL;
CustomButton* button = CustomButton::AsCustomButton(view);
if (!strcmp(view->GetClassName(), CustomButton::kViewClassName)) { if (button) {
CustomButton* button = static_cast<CustomButton*>(view);
if (button->IsHotTracked()) if (button->IsHotTracked())
return button; return button;
} }
for (int i = 0; i < view->child_count(); ++i) { for (int i = 0; i < view->child_count(); ++i) {
View* hot_view = GetFirstHotTrackedView(view->child_at(i)); CustomButton* hot_view = GetFirstHotTrackedView(view->child_at(i));
if (hot_view) if (hot_view)
return hot_view; return hot_view;
} }
...@@ -808,12 +807,9 @@ void MenuController::SetSelection(MenuItemView* menu_item, ...@@ -808,12 +807,9 @@ void MenuController::SetSelection(MenuItemView* menu_item,
bool pending_item_changed = pending_state_.item != menu_item; bool pending_item_changed = pending_state_.item != menu_item;
if (pending_item_changed && pending_state_.item) { if (pending_item_changed && pending_state_.item) {
View* current_hot_view = GetFirstHotTrackedView(pending_state_.item); CustomButton* button = GetFirstHotTrackedView(pending_state_.item);
if (current_hot_view && !strcmp(current_hot_view->GetClassName(), if (button)
CustomButton::kViewClassName)) {
CustomButton* button = static_cast<CustomButton*>(current_hot_view);
button->SetHotTracked(false); button->SetHotTracked(false);
}
} }
// Notify the old path it isn't selected. // Notify the old path it isn't selected.
...@@ -1189,16 +1185,14 @@ MenuController::~MenuController() { ...@@ -1189,16 +1185,14 @@ MenuController::~MenuController() {
MenuController::SendAcceleratorResultType MenuController::SendAcceleratorResultType
MenuController::SendAcceleratorToHotTrackedView() { MenuController::SendAcceleratorToHotTrackedView() {
View* hot_view = GetFirstHotTrackedView(pending_state_.item); CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item);
if (!hot_view) if (!hot_view)
return ACCELERATOR_NOT_PROCESSED; return ACCELERATOR_NOT_PROCESSED;
ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE); ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE);
hot_view->AcceleratorPressed(accelerator); hot_view->AcceleratorPressed(accelerator);
if (!strcmp(hot_view->GetClassName(), CustomButton::kViewClassName)) { CustomButton* button = static_cast<CustomButton*>(hot_view);
CustomButton* button = static_cast<CustomButton*>(hot_view); button->SetHotTracked(true);
button->SetHotTracked(true);
}
return (exit_type_ == EXIT_NONE) ? return (exit_type_ == EXIT_NONE) ?
ACCELERATOR_PROCESSED : ACCELERATOR_PROCESSED_EXIT; ACCELERATOR_PROCESSED : ACCELERATOR_PROCESSED_EXIT;
} }
...@@ -1944,23 +1938,19 @@ void MenuController::IncrementSelection(int delta) { ...@@ -1944,23 +1938,19 @@ void MenuController::IncrementSelection(int delta) {
} }
if (item->has_children()) { if (item->has_children()) {
View* hot_view = GetFirstHotTrackedView(item); CustomButton* button = GetFirstHotTrackedView(item);
if (hot_view && if (button) {
!strcmp(hot_view->GetClassName(), CustomButton::kViewClassName)) {
CustomButton* button = static_cast<CustomButton*>(hot_view);
button->SetHotTracked(false); button->SetHotTracked(false);
View* to_make_hot = GetNextFocusableView(item, button, delta == 1); View* to_make_hot = GetNextFocusableView(item, button, delta == 1);
if (to_make_hot && CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot);
!strcmp(to_make_hot->GetClassName(), CustomButton::kViewClassName)) { if (button_hot) {
CustomButton* button_hot = static_cast<CustomButton*>(to_make_hot);
button_hot->SetHotTracked(true); button_hot->SetHotTracked(true);
return; return;
} }
} else { } else {
View* to_make_hot = GetInitialFocusableView(item, delta == 1); View* to_make_hot = GetInitialFocusableView(item, delta == 1);
if (to_make_hot && CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot);
!strcmp(to_make_hot->GetClassName(), CustomButton::kViewClassName)) { if (button_hot) {
CustomButton* button_hot = static_cast<CustomButton*>(to_make_hot);
button_hot->SetHotTracked(true); button_hot->SetHotTracked(true);
return; return;
} }
...@@ -1979,11 +1969,9 @@ void MenuController::IncrementSelection(int delta) { ...@@ -1979,11 +1969,9 @@ void MenuController::IncrementSelection(int delta) {
break; break;
SetSelection(to_select, SELECTION_DEFAULT); SetSelection(to_select, SELECTION_DEFAULT);
View* to_make_hot = GetInitialFocusableView(to_select, delta == 1); View* to_make_hot = GetInitialFocusableView(to_select, delta == 1);
if (to_make_hot && !strcmp(to_make_hot->GetClassName(), CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot);
CustomButton::kViewClassName)) { if (button_hot)
CustomButton* button_hot = static_cast<CustomButton*>(to_make_hot);
button_hot->SetHotTracked(true); button_hot->SetHotTracked(true);
}
break; break;
} }
} }
......
...@@ -27,11 +27,6 @@ namespace gfx { ...@@ -27,11 +27,6 @@ namespace gfx {
class Font; class Font;
} }
namespace ui {
class MenuModel;
class NativeTheme;
}
namespace views { namespace views {
namespace internal { namespace internal {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment