summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-17 22:45:13 +0000
committerfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-17 22:45:13 +0000
commit0963b3f54b8deb4a8b5b628fe8c9e0579f925f86 (patch)
tree84944fd1e9c64f3aed8421c013078c0c4260cefb /ui
parent26ad5f60da81680b0448dd2d4382d007c3be8421 (diff)
downloadchromium_src-0963b3f54b8deb4a8b5b628fe8c9e0579f925f86.zip
chromium_src-0963b3f54b8deb4a8b5b628fe8c9e0579f925f86.tar.gz
chromium_src-0963b3f54b8deb4a8b5b628fe8c9e0579f925f86.tar.bz2
Revert 137752 - Revert 137059 - Better fix for closing uber tray when clicking on Desktop
Bug=None Test=Manual Review URL: https://chromiumcodereview.appspot.com/9877015 TBR=pkotwicz@chromium.org Review URL: https://chromiumcodereview.appspot.com/10383236 TBR=pkotwicz@chromium.org Review URL: https://chromiumcodereview.appspot.com/10382226 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137755 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/views/bubble/bubble_delegate.cc7
-rw-r--r--ui/views/bubble/bubble_delegate.h1
-rw-r--r--ui/views/widget/widget.cc25
-rw-r--r--ui/views/widget/widget.h9
4 files changed, 33 insertions, 9 deletions
diff --git a/ui/views/bubble/bubble_delegate.cc b/ui/views/bubble/bubble_delegate.cc
index 92645a8..072f355 100644
--- a/ui/views/bubble/bubble_delegate.cc
+++ b/ui/views/bubble/bubble_delegate.cc
@@ -25,6 +25,7 @@ Widget* CreateBubbleWidget(BubbleDelegateView* bubble) {
Widget::InitParams bubble_params(Widget::InitParams::TYPE_BUBBLE);
bubble_params.delegate = bubble;
bubble_params.transparent = true;
+ bubble_params.close_on_deactivate = bubble->close_on_deactivate();
if (bubble->parent_window())
bubble_params.parent = bubble->parent_window();
else
@@ -212,12 +213,6 @@ void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget,
}
}
-void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget,
- bool active) {
- if (close_on_deactivate() && widget == GetWidget() && !active)
- GetWidget()->Close();
-}
-
void BubbleDelegateView::OnWidgetMoved(Widget* widget) {
if (move_with_anchor() && anchor_widget() == widget)
SizeToContents();
diff --git a/ui/views/bubble/bubble_delegate.h b/ui/views/bubble/bubble_delegate.h
index be66f80..25d13f8 100644
--- a/ui/views/bubble/bubble_delegate.h
+++ b/ui/views/bubble/bubble_delegate.h
@@ -50,7 +50,6 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
// Widget::Observer overrides:
virtual void OnWidgetClosing(Widget* widget) OVERRIDE;
virtual void OnWidgetVisibilityChanged(Widget* widget, bool visible) OVERRIDE;
- virtual void OnWidgetActivationChanged(Widget* widget, bool active) OVERRIDE;
virtual void OnWidgetMoved(Widget* widget) OVERRIDE;
bool close_on_esc() const { return close_on_esc_; }
diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc
index e238c67..e5f3072 100644
--- a/ui/views/widget/widget.cc
+++ b/ui/views/widget/widget.cc
@@ -4,6 +4,7 @@
#include "ui/views/widget/widget.h"
+#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/utf_string_conversions.h"
@@ -107,6 +108,7 @@ Widget::InitParams::InitParams()
ViewsDelegate::views_delegate->UseTransparentWindows()),
accept_events(true),
can_activate(true),
+ close_on_deactivate(false),
keep_on_top(false),
ownership(NATIVE_WIDGET_OWNS_WIDGET),
mirror_origin_in_rtl(false),
@@ -131,6 +133,7 @@ Widget::InitParams::InitParams(Type type)
ViewsDelegate::views_delegate->UseTransparentWindows()),
accept_events(true),
can_activate(type != TYPE_POPUP && type != TYPE_MENU),
+ close_on_deactivate(false),
keep_on_top(type == TYPE_MENU),
ownership(NATIVE_WIDGET_OWNS_WIDGET),
mirror_origin_in_rtl(false),
@@ -153,7 +156,8 @@ gfx::NativeView Widget::InitParams::GetParent() const {
// Widget, public:
Widget::Widget()
- : native_widget_(NULL),
+ : ALLOW_THIS_IN_INITIALIZER_LIST(set_capture_factory_(this)),
+ native_widget_(NULL),
widget_delegate_(NULL),
non_client_view_(NULL),
dragged_view_(NULL),
@@ -165,6 +169,7 @@ Widget::Widget()
widget_closed_(false),
saved_show_state_(ui::SHOW_STATE_DEFAULT),
focus_on_creation_(true),
+ close_on_deactivate_(false),
is_top_level_(false),
native_widget_initialized_(false),
native_widget_destroyed_(false),
@@ -316,6 +321,7 @@ void Widget::Init(const InitParams& params) {
SetContentsView(params.delegate->GetContentsView());
SetInitialBoundsForFramelessWindow(params.bounds);
}
+ close_on_deactivate_ = params.close_on_deactivate;
native_widget_initialized_ = true;
}
@@ -511,6 +517,14 @@ void Widget::Show() {
} else {
native_widget_->Show();
}
+
+ if (CanActivate() && close_on_deactivate_) {
+ // Set mouse capture on timeout in case this is called from a
+ // mouse pressed handler.
+ MessageLoopForUI::current()->PostTask(FROM_HERE, base::Bind(
+ &Widget::SetMouseCapture, set_capture_factory_.GetWeakPtr(),
+ static_cast<View*>(NULL)));
+ }
}
void Widget::Hide() {
@@ -1050,6 +1064,8 @@ bool Widget::OnMouseEvent(const MouseEvent& event) {
native_widget_->SetCapture();
return true;
}
+ if (close_on_deactivate_ && !GetRootView()->HitTest(event.location()))
+ Close();
return false;
case ui::ET_MOUSE_RELEASED:
last_mouse_event_was_move_ = false;
@@ -1090,6 +1106,11 @@ void Widget::OnMouseCaptureLost() {
if (is_mouse_button_pressed_)
GetRootView()->OnMouseCaptureLost();
is_mouse_button_pressed_ = false;
+
+ // Without mouse capture, the widget doesn't process all events so can miss
+ // the user clicking outside the root view's bounds.
+ if (close_on_deactivate_)
+ Close();
}
ui::TouchStatus Widget::OnTouchEvent(const TouchEvent& event) {
@@ -1157,7 +1178,7 @@ void Widget::DestroyRootView() {
// Widget, private:
bool Widget::ShouldReleaseCaptureOnMouseReleased() const {
- return true;
+ return !close_on_deactivate_;
}
void Widget::SetInactiveRenderingDisabled(bool value) {
diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h
index c754e95..82ab276 100644
--- a/ui/views/widget/widget.h
+++ b/ui/views/widget/widget.h
@@ -11,6 +11,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "ui/base/accessibility/accessibility_types.h"
#include "ui/base/ui_base_types.h"
@@ -163,6 +164,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
bool transparent;
bool accept_events;
bool can_activate;
+ bool close_on_deactivate;
bool keep_on_top;
Ownership ownership;
bool mirror_origin_in_rtl;
@@ -693,6 +695,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// It's only for testing purpose.
void ReplaceInputMethod(InputMethod* input_method);
+ base::WeakPtrFactory<Widget> set_capture_factory_;
+
internal::NativeWidgetPrivate* native_widget_;
ObserverList<Observer> observers_;
@@ -758,6 +762,11 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// initial focus for the widget.
bool focus_on_creation_;
+ // If true, the widget is closed when the user clicks outside the root view's
+ // bounds. This intentionally encompasses some situations where deactivation
+ // does not happen.
+ bool close_on_deactivate_;
+
scoped_ptr<InputMethod> input_method_;
// See |is_top_level()| accessor.