From 65b541890c5a048796bd2fc9ac687f0bac02bebe Mon Sep 17 00:00:00 2001 From: "sky@chromium.org" Date: Mon, 12 Oct 2009 17:44:40 +0000 Subject: Gets blocked popups to work on views/gtk. I had to fix a couple of additional things here: . Avoid doing anything in OnSizeAllocation if the size hasn't changed. Because of how gtk works I was getting stuck in a loop if I OnSizeAllocate did anything if the size hadn't changed. . Applied similar shortcut to TabContentsViewGtk. . Made SimpleMenuModel only ask delegate for checked state if the item is a check. BUG=none TEST=none Review URL: http://codereview.chromium.org/261051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28716 0039d316-1c4b-4281-b951-d872f2087c98 --- views/controls/menu/simple_menu_model.cc | 4 +++- views/widget/widget_gtk.cc | 9 +++++++++ views/widget/widget_gtk.h | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) (limited to 'views') diff --git a/views/controls/menu/simple_menu_model.cc b/views/controls/menu/simple_menu_model.cc index de86bce..67a9e2d 100644 --- a/views/controls/menu/simple_menu_model.cc +++ b/views/controls/menu/simple_menu_model.cc @@ -103,7 +103,9 @@ bool SimpleMenuModel::GetAcceleratorAt(int index, bool SimpleMenuModel::IsItemCheckedAt(int index) const { if (!delegate_) return false; - return delegate_->IsCommandIdChecked(GetCommandIdAt(index)); + int item_index = FlipIndex(index); + return (items_[item_index].type == TYPE_CHECK) ? + delegate_->IsCommandIdChecked(GetCommandIdAt(index)) : false; } int SimpleMenuModel::GetGroupIdAt(int index) const { diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index cc0aec9..51140a6 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -628,6 +628,15 @@ void WidgetGtk::CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds) { } void WidgetGtk::OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { + // See comment next to size_ as to why we do this. Also note, it's tempting + // to put this in the static method so subclasses don't need to worry about + // it, but if a subclasses needs to set a shape then they need to always + // reset the shape in this method regardless of whether the size changed. + gfx::Size new_size(allocation->width, allocation->height); + if (new_size == size_) + return; + + size_ = new_size; root_view_->SetBounds(0, 0, allocation->width, allocation->height); root_view_->SchedulePaint(); } diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index ccd3bd5..e082eea 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -8,6 +8,7 @@ #include #include "app/active_window_watcher_x.h" +#include "base/gfx/size.h" #include "base/message_loop.h" #include "views/focus/focus_manager.h" #include "views/widget/widget.h" @@ -413,6 +414,12 @@ class WidgetGtk // See make_transient_to_parent for a description. bool transient_to_parent_; + // Last size supplied to OnSizeAllocate. We cache this as any time the + // size of a GtkWidget changes size_allocate is called, even if the size + // didn't change. If we didn't cache this and ignore calls when the size + // hasn't changed, we can end up getting stuck in a never ending loop. + gfx::Size size_; + DISALLOW_COPY_AND_ASSIGN(WidgetGtk); }; -- cgit v1.1