diff options
Diffstat (limited to 'views/controls')
-rw-r--r-- | views/controls/button/text_button.cc | 9 | ||||
-rw-r--r-- | views/controls/button/text_button.h | 6 | ||||
-rw-r--r-- | views/controls/menu/menu_config_gtk.cc | 13 | ||||
-rw-r--r-- | views/controls/menu/menu_controller.cc | 76 | ||||
-rw-r--r-- | views/controls/menu/menu_controller.h | 14 | ||||
-rw-r--r-- | views/controls/menu/menu_host_gtk.cc | 48 | ||||
-rw-r--r-- | views/controls/menu/menu_host_gtk.h | 10 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view.cc | 9 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view_gtk.cc | 88 | ||||
-rw-r--r-- | views/controls/menu/menu_item_view_win.cc | 7 | ||||
-rw-r--r-- | views/controls/menu/menu_scroll_view_container.cc | 3 |
11 files changed, 61 insertions, 222 deletions
diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc index b5733c0..a31f6c9 100644 --- a/views/controls/button/text_button.cc +++ b/views/controls/button/text_button.cc @@ -21,12 +21,9 @@ static const int kIconTextPadding = 5; static const int kPreferredPaddingHorizontal = 6; static const int kPreferredPaddingVertical = 5; -// static -const SkColor TextButton::kEnabledColor = SkColorSetRGB(6, 45, 117); -// static -const SkColor TextButton::kHighlightColor = SkColorSetARGB(200, 255, 255, 255); -// static -const SkColor TextButton::kDisabledColor = SkColorSetRGB(161, 161, 146); +static const SkColor kEnabledColor = SkColorSetRGB(6, 45, 117); +static const SkColor kHighlightColor = SkColorSetARGB(200, 255, 255, 255); +static const SkColor kDisabledColor = SkColorSetRGB(161, 161, 146); // How long the hover fade animation should last. static const int kHoverAnimationDurationMs = 170; diff --git a/views/controls/button/text_button.h b/views/controls/button/text_button.h index 3fbc2b4..e18ef59 100644 --- a/views/controls/button/text_button.h +++ b/views/controls/button/text_button.h @@ -7,7 +7,6 @@ #include "app/gfx/font.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "third_party/skia/include/core/SkColor.h" #include "views/border.h" #include "views/controls/button/custom_button.h" @@ -103,11 +102,6 @@ class TextButton : public CustomButton { virtual gfx::Size GetMinimumSize(); virtual void SetEnabled(bool enabled); - // Text colors. - static const SkColor kEnabledColor; - static const SkColor kHighlightColor; - static const SkColor kDisabledColor; - protected: virtual bool OnMousePressed(const MouseEvent& e); virtual void Paint(gfx::Canvas* canvas); diff --git a/views/controls/menu/menu_config_gtk.cc b/views/controls/menu/menu_config_gtk.cc index acb77ff..1930824 100644 --- a/views/controls/menu/menu_config_gtk.cc +++ b/views/controls/menu/menu_config_gtk.cc @@ -4,23 +4,12 @@ #include "views/controls/menu/menu_config.h" -#include "app/resource_bundle.h" -#include "grit/app_resources.h" -#include "third_party/skia/include/core/SkBitmap.h" - namespace views { // static MenuConfig* MenuConfig::Create() { // TODO: decide what we want this to look like. - MenuConfig* config = new MenuConfig(); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - config->font = rb.GetFont(ResourceBundle::BaseFont); - config->arrow_width = rb.GetBitmapNamed(IDR_MENU_ARROW)->width(); - // Add 4 to force some padding between check and label. - config->check_width = rb.GetBitmapNamed(IDR_MENU_CHECK)->width() + 4; - config->check_height = rb.GetBitmapNamed(IDR_MENU_CHECK)->height(); - return config; + return new MenuConfig(); } } // namespace views diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index c707b60..7c54aa4 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -7,7 +7,6 @@ #include "app/gfx/canvas.h" #include "app/l10n_util.h" #include "app/os_exchange_data.h" -#include "base/keyboard_codes.h" #include "base/time.h" #include "views/controls/menu/menu_scroll_view_container.h" #include "views/controls/menu/submenu_view.h" @@ -346,7 +345,10 @@ void MenuController::OnMousePressed(SubmenuView* source, // event. #if defined(OS_WIN) RepostEvent(source, event); - // NOTE: not reposting on linux seems fine. +#else + // Do we really need the repost logic for linux? I tend to think not but I + // need to verify that + NOTIMPLEMENTED(); #endif // And close. @@ -678,10 +680,10 @@ bool MenuController::Dispatch(const MSG& msg) { // NOTE: focus wasn't changed when the menu was shown. As such, don't // dispatch key events otherwise the focused window will get the events. case WM_KEYDOWN: - return OnKeyDown(msg.wParam, msg); + return OnKeyDown(msg); case WM_CHAR: - return !SelectByChar(static_cast<wchar_t>(msg.wParam)); + return OnChar(msg); case WM_KEYUP: return true; @@ -706,65 +708,35 @@ bool MenuController::Dispatch(const MSG& msg) { return !exit_all_; } -#else -bool MenuController::Dispatch(GdkEvent* event) { - gtk_main_do_event(event); - - if (exit_all_) - return false; - - switch (event->type) { - case GDK_KEY_PRESS: { - if (!OnKeyDown(event->key.keyval)) - return false; - guint32 keycode = gdk_keyval_to_unicode(event->key.keyval); - if (keycode) - return !SelectByChar(keycode); - return true; - } - - default: - break; - } - - return !exit_all_; -} -#endif - -bool MenuController::OnKeyDown(int key_code, -#if defined(OS_WIN) - const MSG& msg -#else -#endif - ) { +bool MenuController::OnKeyDown(const MSG& msg) { DCHECK(blocking_run_); - switch (key_code) { - case base::VKEY_UP: + switch (msg.wParam) { + case VK_UP: IncrementSelection(-1); break; - case base::VKEY_DOWN: + case VK_DOWN: IncrementSelection(1); break; // Handling of VK_RIGHT and VK_LEFT is different depending on the UI // layout. - case base::VKEY_RIGHT: + case VK_RIGHT: if (l10n_util::TextDirection() == l10n_util::RIGHT_TO_LEFT) CloseSubmenu(); else OpenSubmenuChangeSelectionIfCan(); break; - case base::VKEY_LEFT: + case VK_LEFT: if (l10n_util::TextDirection() == l10n_util::RIGHT_TO_LEFT) OpenSubmenuChangeSelectionIfCan(); else CloseSubmenu(); break; - case base::VKEY_RETURN: + case VK_RETURN: if (pending_state_.item) { if (pending_state_.item->HasSubmenu()) { OpenSubmenuChangeSelectionIfCan(); @@ -775,7 +747,7 @@ bool MenuController::OnKeyDown(int key_code, } break; - case base::VKEY_ESCAPE: + case VK_ESCAPE: if (!state_.item->GetParentMenuItem() || (!state_.item->GetParentMenuItem()->GetParentMenuItem() && (!state_.item->HasSubmenu() || @@ -788,20 +760,32 @@ bool MenuController::OnKeyDown(int key_code, } break; -#if defined(OS_WIN) case VK_APPS: break; -#endif default: -#if defined(OS_WIN) TranslateMessage(&msg); -#endif break; } return true; } +bool MenuController::OnChar(const MSG& msg) { + DCHECK(blocking_run_); + + return !SelectByChar(static_cast<wchar_t>(msg.wParam)); +} +#else +bool MenuController::Dispatch(GdkEvent* event) { + gtk_main_do_event(event); + if (exit_all_) + return false; + + NOTIMPLEMENTED(); + return !exit_all_; +} +#endif + MenuController::MenuController(bool blocking) : blocking_run_(blocking), showing_(false), diff --git a/views/controls/menu/menu_controller.h b/views/controls/menu/menu_controller.h index ac84af5..2512ede 100644 --- a/views/controls/menu/menu_controller.h +++ b/views/controls/menu/menu_controller.h @@ -158,17 +158,13 @@ class MenuController : public MessageLoopForUI::Dispatcher { // if the message is such that the menu should be closed. virtual bool Dispatch(const MSG& msg); -#else - virtual bool Dispatch(GdkEvent* event); -#endif - - // Key processing. The return value of this is returned from Dispatch. - // In other words, if this returns false (which happens if escape was + // Key processing. The return value of these is returned from Dispatch. + // In other words, if these return false (which they do if escape was // pressed, or a matching mnemonic was found) the message loop returns. -#if defined(OS_WIN) - bool OnKeyDown(int key_code, const MSG& msg); + bool OnKeyDown(const MSG& msg); + bool OnChar(const MSG& msg); #else - bool OnKeyDown(int key_code); + virtual bool Dispatch(GdkEvent* event); #endif // Creates a MenuController. If blocking is true, Run blocks the caller diff --git a/views/controls/menu/menu_host_gtk.cc b/views/controls/menu/menu_host_gtk.cc index 9990aab..b87aa23 100644 --- a/views/controls/menu/menu_host_gtk.cc +++ b/views/controls/menu/menu_host_gtk.cc @@ -17,8 +17,7 @@ namespace views { MenuHost::MenuHost(SubmenuView* submenu) : WidgetGtk(WidgetGtk::TYPE_POPUP), closed_(false), - submenu_(submenu), - did_pointer_grab_(false) { + submenu_(submenu) { // TODO(sky): make sure this is needed. GdkModifierType current_event_mod; if (gtk_get_current_event_state(¤t_event_mod)) { @@ -40,26 +39,7 @@ void MenuHost::Init(gfx::NativeView parent, // TODO(sky): see if there is some way to show without changing focus. Show(); if (do_capture) { - // Release the current grab. - GtkWidget* current_grab_window = gtk_grab_get_current(); - if (current_grab_window) - gtk_grab_remove(current_grab_window); - - // Make sure all app mouse events are targetted at us only. DoGrab(); - - // And do a grab. - // NOTE: we do this to ensure we get mouse events from other apps, a grab - // done with gtk_grab_add doesn't get events from other apps. - GdkGrabStatus grab_status = - gdk_pointer_grab(window_contents()->window, FALSE, - static_cast<GdkEventMask>( - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK), - NULL, NULL, GDK_CURRENT_TIME); - did_pointer_grab_ = (grab_status == GDK_GRAB_SUCCESS); - DCHECK(did_pointer_grab_); - // need keyboard grab. #ifdef DEBUG_MENU DLOG(INFO) << "Doing capture"; #endif @@ -81,8 +61,8 @@ void MenuHost::Hide() { // remove them so that View doesn't try to access deleted objects. static_cast<MenuHostRootView*>(GetRootView())->suspend_events(); GetRootView()->RemoveAllChildViews(false); - ReleaseGrab(); closed_ = true; + ReleaseGrab(); WidgetGtk::Hide(); } @@ -100,16 +80,14 @@ RootView* MenuHost::CreateRootView() { return new MenuHostRootView(this, submenu_); } -gboolean MenuHost::OnGrabBrokeEvent(GtkWidget* widget, GdkEvent* event) { - if (!closed_) - submenu_->GetMenuItem()->GetMenuController()->Cancel(true); - return WidgetGtk::OnGrabBrokeEvent(widget, event); -} - -void MenuHost::OnGrabNotify(GtkWidget* widget, gboolean was_grabbed) { - if (!closed_ && (widget != window_contents() || !was_grabbed)) +void MenuHost::OnCancelMode() { + // TODO(sky): see if there is an equivalent to this. + if (!closed_) { +#ifdef DEBUG_MENU + DLOG(INFO) << "OnCanceMode, closing menu"; +#endif submenu_->GetMenuItem()->GetMenuController()->Cancel(true); - WidgetGtk::OnGrabNotify(widget, was_grabbed); + } } // Overriden to return false, we do NOT want to release capture on mouse @@ -118,12 +96,4 @@ bool MenuHost::ReleaseCaptureOnMouseReleased() { return false; } -void MenuHost::ReleaseGrab() { - WidgetGtk::ReleaseGrab(); - if (did_pointer_grab_) { - did_pointer_grab_ = false; - gdk_pointer_ungrab(GDK_CURRENT_TIME); - } -} - } // namespace views diff --git a/views/controls/menu/menu_host_gtk.h b/views/controls/menu/menu_host_gtk.h index 6e70bc9..545acb5 100644 --- a/views/controls/menu/menu_host_gtk.h +++ b/views/controls/menu/menu_host_gtk.h @@ -30,17 +30,12 @@ class MenuHost : public WidgetGtk { protected: virtual RootView* CreateRootView(); - // If the grab breaks we cancel the menu. - virtual gboolean OnGrabBrokeEvent(GtkWidget* widget, GdkEvent* event); - virtual void OnGrabNotify(GtkWidget* widget, gboolean was_grabbed); + virtual void OnCancelMode(); // Overriden to return false, we do NOT want to release capture on mouse // release. virtual bool ReleaseCaptureOnMouseReleased(); - // Overriden to also release pointer grab. - virtual void ReleaseGrab(); - private: // If true, we've been closed. bool closed_; @@ -48,9 +43,6 @@ class MenuHost : public WidgetGtk { // The view we contain. SubmenuView* submenu_; - // Have we done a pointer grab? - bool did_pointer_grab_; - DISALLOW_COPY_AND_ASSIGN(MenuHost); }; diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index 7a6056f..6308b52 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -53,9 +53,11 @@ bool MenuItemView::allow_task_nesting_during_run_ = false; // static int MenuItemView::label_start_; +// Margins between the right of the item and the label. // static int MenuItemView::item_right_margin_; +// Preferred height of menu items. Reset every time a menu is run. // static int MenuItemView::pref_menu_height_; @@ -187,6 +189,13 @@ void MenuItemView::Paint(gfx::Canvas* canvas) { Paint(canvas, false); } +gfx::Size MenuItemView::GetPreferredSize() { + const gfx::Font& font = MenuConfig::instance().font; + return gfx::Size( + font.GetStringWidth(title_) + label_start_ + item_right_margin_, + font.height() + GetBottomMargin() + GetTopMargin()); +} + MenuController* MenuItemView::GetMenuController() { return GetRootMenuItem()->controller_; } diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc index 33e5ff4..6f5b8e4 100644 --- a/views/controls/menu/menu_item_view_gtk.cc +++ b/views/controls/menu/menu_item_view_gtk.cc @@ -4,97 +4,13 @@ #include "views/controls/menu/menu_item_view.h" -#include "app/gfx/canvas.h" -#include "app/gfx/favicon_size.h" -#include "app/resource_bundle.h" -#include "grit/app_resources.h" -#include "views/controls/button/text_button.h" +#include "base/logging.h" #include "views/controls/menu/menu_config.h" -#include "views/controls/menu/submenu_view.h" namespace views { -// Background color when the menu item is selected. -static const SkColor kSelectedBackgroundColor = SkColorSetRGB(246, 249, 253); - -gfx::Size MenuItemView::GetPreferredSize() { - const gfx::Font& font = MenuConfig::instance().font; - // TODO(sky): this is a workaround until I figure out why font.height() - // isn't returning the right thing. We really only want to include - // kFavIconSize if we're showing icons. - int content_height = std::max(kFavIconSize, font.height()); - return gfx::Size( - font.GetStringWidth(title_) + label_start_ + item_right_margin_, - content_height + GetBottomMargin() + GetTopMargin()); -} - void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { - const MenuConfig& config = MenuConfig::instance(); - bool render_selection = - (!for_drag && IsSelected() && - parent_menu_item_->GetSubmenu()->GetShowSelection(this)); - - int icon_x = config.item_left_margin; - int top_margin = GetTopMargin(); - int bottom_margin = GetBottomMargin(); - int icon_y = top_margin + (height() - config.item_top_margin - - bottom_margin - config.check_height) / 2; - int icon_height = config.check_height; - int available_height = height() - top_margin - bottom_margin; - - // Render the background. As MenuScrollViewContainer draws the background, we - // only need the background when we want it to look different, as when we're - // selected. - if (render_selection) - canvas->drawColor(kSelectedBackgroundColor, SkXfermode::kSrc_Mode); - - // Render the check. - if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - SkBitmap* check = rb.GetBitmapNamed(IDR_MENU_CHECK); - // Don't use config.check_width here as it's padded to force more padding. - gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); - AdjustBoundsForRTLUI(&check_bounds); - canvas->DrawBitmapInt(*check, check_bounds.x(), check_bounds.y()); - } - - // Render the foreground. - SkColor fg_color = - IsEnabled() ? TextButton::kEnabledColor : TextButton::kDisabledColor; - int width = this->width() - item_right_margin_ - label_start_; - const gfx::Font& font = MenuConfig::instance().font; - gfx::Rect text_bounds(label_start_, top_margin + - (available_height - font.height()) / 2, width, - font.height()); - text_bounds.set_x(MirroredLeftPointForRect(text_bounds)); - canvas->DrawStringInt(GetTitle(), font, fg_color, - text_bounds.x(), text_bounds.y(), text_bounds.width(), - text_bounds.height(), - GetRootMenuItem()->GetDrawStringFlags()); - - // Render the icon. - if (icon_.width() > 0) { - gfx::Rect icon_bounds(config.item_left_margin, - top_margin + (height() - top_margin - - bottom_margin - icon_.height()) / 2, - icon_.width(), - icon_.height()); - icon_bounds.set_x(MirroredLeftPointForRect(icon_bounds)); - canvas->DrawBitmapInt(icon_, icon_bounds.x(), icon_bounds.y()); - } - - // Render the submenu indicator (arrow). - if (HasSubmenu()) { - gfx::Rect arrow_bounds(this->width() - item_right_margin_ + - config.label_to_arrow_padding, - top_margin + (available_height - - config.arrow_width) / 2, - config.arrow_width, height()); - AdjustBoundsForRTLUI(&arrow_bounds); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - canvas->DrawBitmapInt(*rb.GetBitmapNamed(IDR_MENU_ARROW), - arrow_bounds.x(), arrow_bounds.y()); - } + NOTIMPLEMENTED(); } } // namespace views diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc index 8ec80eb3..8f3812c 100644 --- a/views/controls/menu/menu_item_view_win.cc +++ b/views/controls/menu/menu_item_view_win.cc @@ -19,13 +19,6 @@ using gfx::NativeTheme; namespace views { -gfx::Size MenuItemView::GetPreferredSize() { - const gfx::Font& font = MenuConfig::instance().font; - return gfx::Size( - font.GetStringWidth(title_) + label_start_ + item_right_margin_, - font.height() + GetBottomMargin() + GetTopMargin()); -} - void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { const MenuConfig& config = MenuConfig::instance(); bool render_selection = diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc index b50e926..45a4777 100644 --- a/views/controls/menu/menu_scroll_view_container.cc +++ b/views/controls/menu/menu_scroll_view_container.cc @@ -185,8 +185,7 @@ void MenuScrollViewContainer::Paint(gfx::Canvas* canvas) { NativeTheme::MENU, dc, MENU_POPUPBACKGROUND, 0, &bounds); canvas->endPlatformPaint(); #else - // This is the same as COLOR_TOOLBAR. - canvas->drawColor(SkColorSetRGB(210, 225, 246), SkXfermode::kSrc_Mode); + NOTIMPLEMENTED(); #endif } |