summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 00:55:33 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 00:55:33 +0000
commitde3fe87c9a3147596642b78805de4202b0523d29 (patch)
tree0b7bc92939be40fe86c12934bde08b3f95d1fce2 /views
parent6f5e4e1490f6309b12b1fc313918c09eea573ceb (diff)
downloadchromium_src-de3fe87c9a3147596642b78805de4202b0523d29.zip
chromium_src-de3fe87c9a3147596642b78805de4202b0523d29.tar.gz
chromium_src-de3fe87c9a3147596642b78805de4202b0523d29.tar.bz2
Add SubmenuView::magic_token_ and checks.
Add MenuHostRootView::destroyed_flag_ and check. May help identify the cause of crbug.com/78792. Minor refactoring / code consolidation. BUG=78792 TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=82385 Review URL: http://codereview.chromium.org/6879059 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82596 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/menu/menu_host_root_view.cc17
-rw-r--r--views/controls/menu/menu_host_root_view.h6
-rw-r--r--views/controls/menu/submenu_view.cc49
-rw-r--r--views/controls/menu/submenu_view.h7
4 files changed, 53 insertions, 26 deletions
diff --git a/views/controls/menu/menu_host_root_view.cc b/views/controls/menu/menu_host_root_view.cc
index dee5472..405eaf8 100644
--- a/views/controls/menu/menu_host_root_view.cc
+++ b/views/controls/menu/menu_host_root_view.cc
@@ -13,14 +13,23 @@ MenuHostRootView::MenuHostRootView(Widget* widget,
SubmenuView* submenu)
: RootView(widget),
submenu_(submenu),
- forward_drag_to_menu_controller_(true) {
+ forward_drag_to_menu_controller_(true),
+ destroyed_flag_ (NULL) {
+}
+
+MenuHostRootView::~MenuHostRootView() {
+ if(destroyed_flag_)
+ *destroyed_flag_ = true;
}
bool MenuHostRootView::OnMousePressed(const MouseEvent& event) {
+ bool destroyed = false;
+ destroyed_flag_ = &destroyed;
forward_drag_to_menu_controller_ =
- ((event.x() < 0 || event.y() < 0 || event.x() >= width() ||
- event.y() >= height()) ||
- !RootView::OnMousePressed(event));
+ !GetLocalBounds().Contains(event.location()) ||
+ !RootView::OnMousePressed(event);
+ CHECK(!destroyed);
+ destroyed_flag_ = NULL;
if (forward_drag_to_menu_controller_ && GetMenuController())
GetMenuController()->OnMousePressed(submenu_, event);
return true;
diff --git a/views/controls/menu/menu_host_root_view.h b/views/controls/menu/menu_host_root_view.h
index ccd5247..6ff0c16 100644
--- a/views/controls/menu/menu_host_root_view.h
+++ b/views/controls/menu/menu_host_root_view.h
@@ -22,6 +22,7 @@ class SubmenuView;
class MenuHostRootView : public RootView {
public:
MenuHostRootView(Widget* widget, SubmenuView* submenu);
+ ~MenuHostRootView();
// Overridden from View:
virtual bool OnMousePressed(const MouseEvent& event) OVERRIDE;
@@ -40,6 +41,11 @@ class MenuHostRootView : public RootView {
// Whether mouse dragged/released should be forwarded to the MenuController.
bool forward_drag_to_menu_controller_;
+ // TODO(msw): Resolve crasher crbug.com/78792.
+ // If non-null the destructor sets this to true. This is set to non-null
+ // during RootView::OnMousePressed to detect unplanned destruction.
+ bool* destroyed_flag_;
+
DISALLOW_COPY_AND_ASSIGN(MenuHostRootView);
};
diff --git a/views/controls/menu/submenu_view.cc b/views/controls/menu/submenu_view.cc
index 117496d..a0d3f12 100644
--- a/views/controls/menu/submenu_view.cc
+++ b/views/controls/menu/submenu_view.cc
@@ -13,11 +13,19 @@
#include "views/widget/root_view.h"
#include "views/widget/widget.h"
+namespace {
+
// Height of the drop indicator. This should be an even number.
-static const int kDropIndicatorHeight = 2;
+const int kDropIndicatorHeight = 2;
// Color of the drop indicator.
-static const SkColor kDropIndicatorColor = SK_ColorBLACK;
+const SkColor kDropIndicatorColor = SK_ColorBLACK;
+
+// TODO(msw): Resolve crasher crbug.com/78792.
+const int kMagicInitialized = 0x346292;
+const int kMagicDestroyed = 0x9932CD;
+
+} // namespace
namespace views {
@@ -33,18 +41,23 @@ SubmenuView::SubmenuView(MenuItemView* parent)
drop_item_(NULL),
drop_position_(MenuDelegate::DROP_NONE),
scroll_view_container_(NULL),
- max_accelerator_width_(0) {
+ max_accelerator_width_(0),
+ magic_token_(kMagicInitialized) {
DCHECK(parent);
// We'll delete ourselves, otherwise the ScrollView would delete us on close.
set_parent_owned(false);
}
SubmenuView::~SubmenuView() {
+ CHECK_EQ(magic_token_, kMagicInitialized);
+
// The menu may not have been closed yet (it will be hidden, but not
// necessarily closed).
Close();
delete scroll_view_container_;
+
+ magic_token_ = kMagicDestroyed;
}
int SubmenuView::GetMenuItemCount() {
@@ -229,25 +242,15 @@ void SubmenuView::ShowAt(gfx::NativeWindow parent,
bool do_capture) {
if (host_) {
host_->ShowMenuHost(do_capture);
-
- GetScrollViewContainer()->GetWidget()->NotifyAccessibilityEvent(
- GetScrollViewContainer(),
- ui::AccessibilityTypes::EVENT_MENUSTART,
- true);
- GetWidget()->NotifyAccessibilityEvent(
- this,
- ui::AccessibilityTypes::EVENT_MENUPOPUPSTART,
- true);
- return;
+ } else {
+ host_ = new MenuHost(this);
+ // Force construction of the scroll view container.
+ GetScrollViewContainer();
+ // Make sure the first row is visible.
+ ScrollRectToVisible(gfx::Rect(gfx::Point(), gfx::Size(1, 1)));
+ host_->InitMenuHost(parent, bounds, scroll_view_container_, do_capture);
}
- host_ = new MenuHost(this);
- // Force construction of the scroll view container.
- GetScrollViewContainer();
- // Make sure the first row is visible.
- ScrollRectToVisible(gfx::Rect(gfx::Point(), gfx::Size(1, 1)));
- host_->InitMenuHost(parent, bounds, scroll_view_container_, do_capture);
-
GetScrollViewContainer()->GetWidget()->NotifyAccessibilityEvent(
GetScrollViewContainer(),
ui::AccessibilityTypes::EVENT_MENUSTART,
@@ -293,6 +296,11 @@ bool SubmenuView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
return views::FocusManager::IsTabTraversalKeyEvent(e);
}
+MenuItemView* SubmenuView::GetMenuItem() const {
+ CHECK_EQ(magic_token_, kMagicInitialized);
+ return parent_menu_item_;
+}
+
void SubmenuView::SetDropMenuItem(MenuItemView* item,
MenuDelegate::DropPosition position) {
if (drop_item_ == item && drop_position_ == position)
@@ -313,6 +321,7 @@ bool SubmenuView::GetShowSelection(MenuItemView* item) {
}
MenuScrollViewContainer* SubmenuView::GetScrollViewContainer() {
+ CHECK_EQ(magic_token_, kMagicInitialized);
if (!scroll_view_container_) {
scroll_view_container_ = new MenuScrollViewContainer(this);
// Otherwise MenuHost would delete us.
diff --git a/views/controls/menu/submenu_view.h b/views/controls/menu/submenu_view.h
index 50f9a6b..f0bed4a 100644
--- a/views/controls/menu/submenu_view.h
+++ b/views/controls/menu/submenu_view.h
@@ -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.
@@ -107,7 +107,7 @@ class SubmenuView : public View {
virtual bool SkipDefaultKeyEventProcessing(const KeyEvent& e);
// Returns the parent menu item we're showing children for.
- MenuItemView* GetMenuItem() const { return parent_menu_item_; }
+ MenuItemView* GetMenuItem() const;
// Set the drop item and position.
void SetDropMenuItem(MenuItemView* item,
@@ -176,6 +176,9 @@ class SubmenuView : public View {
// See description above getter.
int max_accelerator_width_;
+ // TODO(msw): Resolve crasher crbug.com/78792.
+ int magic_token_;
+
DISALLOW_COPY_AND_ASSIGN(SubmenuView);
};