diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-07 17:14:23 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-07 17:14:23 +0000 |
commit | 8784578d7e13d112fd205d3ee4fc1fe0018beea0 (patch) | |
tree | 13cb5188f82350fef1c18ffe34951059609fafdb | |
parent | 70b1969691d983965f272d6fc05b252582fe0ee9 (diff) | |
download | chromium_src-8784578d7e13d112fd205d3ee4fc1fe0018beea0.zip chromium_src-8784578d7e13d112fd205d3ee4fc1fe0018beea0.tar.gz chromium_src-8784578d7e13d112fd205d3ee4fc1fe0018beea0.tar.bz2 |
MessageBubble which does not require separate window and does not grab input on mouse press event.
* Added new constructor to InfoBubble for chromeos which takes WidgetGtk::Type parameter
* Made DoGrab/HandleGrabBroke so that subclass can customize its behavior.
* Added MessageBubble::ShowNoGrab that shows a child MessageBubble which does not grab input on mouse press event.
* Explicitly remove accelerator when closed. This is necessary for child, but doing for all case as it's harmless to do so.
* Moved HandleGrabBroke to protected and made virtual so that sub class
can trap the event. ScreenLocker will use this event to detect this.
This will be used for screen locker.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2682004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49068 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/login/message_bubble.cc | 31 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/message_bubble.h | 23 | ||||
-rw-r--r-- | chrome/browser/views/info_bubble.cc | 13 | ||||
-rw-r--r-- | chrome/browser/views/info_bubble.h | 3 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 18 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 9 |
6 files changed, 78 insertions, 19 deletions
diff --git a/chrome/browser/chromeos/login/message_bubble.cc b/chrome/browser/chromeos/login/message_bubble.cc index 36071b5..3c69f89 100644 --- a/chrome/browser/chromeos/login/message_bubble.cc +++ b/chrome/browser/chromeos/login/message_bubble.cc @@ -19,8 +19,11 @@ namespace chromeos { static const int kBorderSize = 4; static const int kMaxLabelWidth = 250; -MessageBubble::MessageBubble(views::Widget* parent, SkBitmap* image, - const std::wstring& text) : parent_(parent) { +MessageBubble::MessageBubble(views::WidgetGtk::Type type, views::Widget* parent, + SkBitmap* image, const std::wstring& text, bool grab_enabled) + : InfoBubble(type), + parent_(parent), + grab_enabled_(grab_enabled) { using views::GridLayout; views::View* control_view = new views::View(); @@ -76,7 +79,24 @@ MessageBubble* MessageBubble::Show(views::Widget* parent, const std::wstring& text, InfoBubbleDelegate* delegate) { // The bubble will be destroyed when it is closed. - MessageBubble* bubble = new MessageBubble(parent, image, text); + MessageBubble* bubble = new MessageBubble( + views::WidgetGtk::TYPE_WINDOW, parent, image, text, true); + bubble->Init(parent, position_relative_to, arrow_location, + bubble->text_->GetParent(), delegate); + return bubble; +} + +// static +MessageBubble* MessageBubble::ShowNoGrab( + views::Widget* parent, + const gfx::Rect& position_relative_to, + BubbleBorder::ArrowLocation arrow_location, + SkBitmap* image, + const std::wstring& text, + InfoBubbleDelegate* delegate) { + // The bubble will be destroyed when it is closed. + MessageBubble* bubble = new MessageBubble( + views::WidgetGtk::TYPE_CHILD, parent, image, text, false); bubble->Init(parent, position_relative_to, arrow_location, bubble->text_->GetParent(), delegate); return bubble; @@ -91,6 +111,11 @@ void MessageBubble::IsActiveChanged() { } } +void MessageBubble::DoGrab() { + if (grab_enabled_) + WidgetGtk::DoGrab(); +} + void MessageBubble::Close() { parent_ = NULL; InfoBubble::Close(); diff --git a/chrome/browser/chromeos/login/message_bubble.h b/chrome/browser/chromeos/login/message_bubble.h index 82f9cbe..9bc4464 100644 --- a/chrome/browser/chromeos/login/message_bubble.h +++ b/chrome/browser/chromeos/login/message_bubble.h @@ -8,6 +8,7 @@ #include "chrome/browser/views/info_bubble.h" #include "views/controls/button/button.h" #include "views/view.h" +#include "views/widget/widget_gtk.h" class SkBitmap; @@ -31,23 +32,39 @@ class MessageBubble : public InfoBubble, const std::wstring& text, InfoBubbleDelegate* delegate); - // Overridden from WidgetWin + // Create and show bubble which does not grab pointer. This creates + // a TYPE_CHILD WidgetGtk and |position_relative_to| must be in parent's + // coordinates. + static MessageBubble* ShowNoGrab(views::Widget* parent, + const gfx::Rect& position_relative_to, + BubbleBorder::ArrowLocation arrow_location, + SkBitmap* image, + const std::wstring& text, + InfoBubbleDelegate* delegate); + + // Overridden from WidgetGtk. virtual void Close(); protected: + + // views::ButtonListener implmenets. virtual void ButtonPressed(views::Button* sender, const views::Event& event); + // Overridden from WidgetGtk. virtual void IsActiveChanged(); + virtual void DoGrab(); private: - MessageBubble(views::Widget* parent, SkBitmap* image, - const std::wstring& text); + MessageBubble(views::WidgetGtk::Type type, + views::Widget* parent, SkBitmap* image, + const std::wstring& text, bool grab_enabled); views::Widget* parent_; views::ImageView* icon_; views::Label* text_; views::ImageButton* close_button_; + bool grab_enabled_; DISALLOW_COPY_AND_ASSIGN(MessageBubble); }; diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc index 41907af..d2d6c4a 100644 --- a/chrome/browser/views/info_bubble.cc +++ b/chrome/browser/views/info_bubble.cc @@ -249,6 +249,9 @@ InfoBubble* InfoBubble::Show(views::Widget* parent, } void InfoBubble::Close() { + GetFocusManager()->UnregisterAccelerator( + views::Accelerator(base::VKEY_ESCAPE, false, false, false), this); + if (fade_away_on_close_) FadeOut(); else @@ -298,6 +301,16 @@ InfoBubble::InfoBubble() fade_away_on_close_(false) { } +#if defined(OS_CHROMEOS) +InfoBubble::InfoBubble(views::WidgetGtk::Type type) + : WidgetGtk(type), + border_contents_(NULL), + delegate_(NULL), + closed_(false), + fade_away_on_close_(false) { +} +#endif + void InfoBubble::Init(views::Widget* parent, const gfx::Rect& position_relative_to, BubbleBorder::ArrowLocation arrow_location, diff --git a/chrome/browser/views/info_bubble.h b/chrome/browser/views/info_bubble.h index a26c21b..962ac2f 100644 --- a/chrome/browser/views/info_bubble.h +++ b/chrome/browser/views/info_bubble.h @@ -216,6 +216,9 @@ class InfoBubble protected: InfoBubble(); +#if defined(OS_CHROMEOS) + explicit InfoBubble(views::WidgetGtk::Type type); +#endif virtual ~InfoBubble() {} // Creates the InfoBubble. diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 78137c5..5d946f5 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -1153,6 +1153,15 @@ void WidgetGtk::ReleaseGrab() { } } +void WidgetGtk::HandleGrabBroke() { + if (has_capture_) { + if (is_mouse_down_) + root_view_->ProcessMouseDragCanceled(); + is_mouse_down_ = false; + has_capture_ = false; + } +} + //////////////////////////////////////////////////////////////////////////////// // WidgetGtk, private: @@ -1399,15 +1408,6 @@ void WidgetGtk::ConfigureWidgetForIgnoreEvents() { 0); } -void WidgetGtk::HandleGrabBroke() { - if (has_capture_) { - if (is_mouse_down_) - root_view_->ProcessMouseDragCanceled(); - is_mouse_down_ = false; - has_capture_ = false; - } -} - void WidgetGtk::DrawTransparentBackground(GtkWidget* widget, GdkEventExpose* event) { cairo_t* cr = gdk_cairo_create(widget->window); diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index beb629f..8f7ca17 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -270,11 +270,15 @@ class WidgetGtk virtual bool ReleaseCaptureOnMouseReleased() { return true; } // Does a mouse grab on this widget. - void DoGrab(); + virtual void DoGrab(); // Releases a grab done by this widget. virtual void ReleaseGrab(); + // Invoked when input grab is stolen by other GtkWidget in the same + // application. + virtual void HandleGrabBroke(); + // Are we a subclass of WindowGtk? bool is_window_; @@ -316,9 +320,6 @@ class WidgetGtk // MakeIgnoreEvents has been invoked. void ConfigureWidgetForIgnoreEvents(); - // TODO(sky): documentation - void HandleGrabBroke(); - // A utility function to draw a transparent background onto the |widget|. static void DrawTransparentBackground(GtkWidget* widget, GdkEventExpose* event); |