diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-11 20:43:16 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-11 20:43:16 +0000 |
commit | 51a4dc719239e4c22b64fc641251443f09022300 (patch) | |
tree | 2e5267a7c934c305ae8f3147ffdc4be847ce3189 | |
parent | 0edfffdee7e6b18247190e1aec262a711fa9aa3f (diff) | |
download | chromium_src-51a4dc719239e4c22b64fc641251443f09022300.zip chromium_src-51a4dc719239e4c22b64fc641251443f09022300.tar.gz chromium_src-51a4dc719239e4c22b64fc641251443f09022300.tar.bz2 |
Rebase BookmarkBubble on the new views bubble.
Use a View instead of a Point for anchoring the bubble.
Remove the now unused IDS_BOOKMARK_BUBBLE_ADD_BOOKMARK.
Remove the unused BubbleDelegate base class from StarView.
BUG=97248,98312,98323
TEST=Bookmark bubble has the same behavior/appearance.
Review URL: http://codereview.chromium.org/8368016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109688 0039d316-1c4b-4281-b951-d872f2087c98
19 files changed, 159 insertions, 290 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index f48ebf8..cc2d66c 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -6686,9 +6686,6 @@ Keep your key file in a safe place. You will need it to create new versions of y </message> <!-- bookmark info bubble messages --> - <message name="IDS_BOOKMARK_BUBBLE_ADD_BOOKMARK" desc="Accessible title of the bubble before bookmarking something"> - Add Bookmark - </message> <message name="IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED" desc="Title of the bubble after bookmarking something"> Bookmark Added! </message> diff --git a/chrome/browser/chromeos/setting_level_bubble.cc b/chrome/browser/chromeos/setting_level_bubble.cc index daaf3b2..650c252 100644 --- a/chrome/browser/chromeos/setting_level_bubble.cc +++ b/chrome/browser/chromeos/setting_level_bubble.cc @@ -138,9 +138,7 @@ gfx::Point SettingLevelBubbleDelegateView::GetAnchorPoint() { SettingLevelBubbleDelegateView::SettingLevelBubbleDelegateView( views::Widget* parent) - : BubbleDelegateView(gfx::Point(), - views::BubbleBorder::FLOAT, - SK_ColorWHITE), + : BubbleDelegateView(NULL, views::BubbleBorder::FLOAT, SK_ColorWHITE), parent_(parent), view_(NULL) { set_close_on_esc(false); @@ -238,8 +236,7 @@ SettingLevelBubbleView* SettingLevelBubble::CreateView() { views::Widget* parent = GetToplevelWidget(); SettingLevelBubbleDelegateView* delegate = new SettingLevelBubbleDelegateView(parent); - views::Widget* widget = - views::BubbleDelegateView::CreateBubble(delegate, parent); + views::Widget* widget = views::BubbleDelegateView::CreateBubble(delegate); widget->AddObserver(this); #if !defined(USE_AURA) diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc index b9a76af..dead673 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc @@ -14,7 +14,6 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/views/bubble/bubble.h" #include "chrome/common/chrome_notification_types.h" #include "content/browser/user_metrics.h" #include "content/public/browser/notification_service.h" @@ -23,20 +22,14 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" #include "views/controls/button/text_button.h" #include "views/controls/label.h" #include "views/controls/link.h" #include "views/controls/textfield/textfield.h" #include "views/events/event.h" -#include "views/focus/focus_manager.h" #include "views/layout/grid_layout.h" #include "views/layout/layout_constants.h" -#include "views/window/client_view.h" - -#if defined(TOOLKIT_USES_GTK) -#include "views/widget/native_widget_gtk.h" -#endif +#include "views/widget/widget.h" using views::ColumnSet; using views::GridLayout; @@ -50,18 +43,18 @@ static const int kTitlePadding = 4; // of the field's left edge. static const int kMinimumFieldSize = 180; +// TODO(msw): Get color from theme/window color. +static const SkColor kColor = SK_ColorWHITE; + // Declared in browser_dialogs.h so callers don't have to depend on our header. namespace browser { -void ShowBookmarkBubbleView(views::Widget* parent, - const gfx::Rect& bounds, - BubbleDelegate* delegate, +void ShowBookmarkBubbleView(views::View* anchor_view, Profile* profile, const GURL& url, bool newly_bookmarked) { - BookmarkBubbleView::Show(parent, bounds, delegate, profile, url, - newly_bookmarked); + BookmarkBubbleView::ShowBubble(anchor_view, profile, url, newly_bookmarked); } void HideBookmarkBubbleView() { @@ -79,30 +72,20 @@ bool IsBookmarkBubbleViewShowing() { BookmarkBubbleView* BookmarkBubbleView::bookmark_bubble_ = NULL; // static -void BookmarkBubbleView::Show(views::Widget* parent, - const gfx::Rect& bounds, - BubbleDelegate* delegate, - Profile* profile, - const GURL& url, - bool newly_bookmarked) { +void BookmarkBubbleView::ShowBubble(views::View* anchor_view, + Profile* profile, + const GURL& url, + bool newly_bookmarked) { if (IsShowing()) return; - bookmark_bubble_ = new BookmarkBubbleView(delegate, profile, url, - newly_bookmarked); - Bubble* bubble = Bubble::Show( - parent, bounds, views::BubbleBorder::TOP_RIGHT, - views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bookmark_bubble_, - bookmark_bubble_); - // |bubble_| can be set to NULL in BubbleClosing when we close the bubble - // asynchronously. However, that can happen during the Show call above if the - // window loses activation while we are getting to ready to show the bubble, - // so we must check to make sure we still have a valid bubble before - // proceeding. - if (!bookmark_bubble_) - return; - bookmark_bubble_->set_bubble(bubble); - bubble->SizeToContents(); + bookmark_bubble_ = + new BookmarkBubbleView(anchor_view, profile, url, newly_bookmarked); + views::BubbleDelegateView::CreateBubble(bookmark_bubble_); + bookmark_bubble_->Show(); + // Select the entire title textfield contents when the bubble is first shown. + bookmark_bubble_->title_tf_->SelectAll(); + GURL url_ptr(url); content::NotificationService::current()->Notify( chrome::NOTIFICATION_BOOKMARK_BUBBLE_SHOWN, @@ -117,7 +100,7 @@ bool BookmarkBubbleView::IsShowing() { void BookmarkBubbleView::Hide() { if (IsShowing()) - bookmark_bubble_->Close(); + bookmark_bubble_->GetWidget()->Close(); } BookmarkBubbleView::~BookmarkBubbleView() { @@ -131,54 +114,47 @@ BookmarkBubbleView::~BookmarkBubbleView() { } } -void BookmarkBubbleView::BubbleShown() { - DCHECK(GetWidget()); - GetFocusManager()->RegisterAccelerator( - views::Accelerator(ui::VKEY_RETURN, false, false, false), this); +views::View* BookmarkBubbleView::GetInitiallyFocusedView() { + return title_tf_; +} - title_tf_->RequestFocus(); - title_tf_->SelectAll(); +gfx::Point BookmarkBubbleView::GetAnchorPoint() { + // Compensate for some built-in padding in the star image. + return BubbleDelegateView::GetAnchorPoint().Subtract(gfx::Point(0, 5)); } -bool BookmarkBubbleView::AcceleratorPressed( - const views::Accelerator& accelerator) { - if (accelerator.key_code() != ui::VKEY_RETURN) - return false; +void BookmarkBubbleView::WindowClosing() { + // We have to reset |bubble_| here, not in our destructor, because we'll be + // destroyed asynchronously and the shown state will be checked before then. + DCHECK(bookmark_bubble_ == this); + bookmark_bubble_ = NULL; - if (edit_button_->HasFocus()) - HandleButtonPressed(edit_button_); - else - HandleButtonPressed(close_button_); - return true; -} + content::NotificationService::current()->Notify( + chrome::NOTIFICATION_BOOKMARK_BUBBLE_HIDDEN, + content::Source<Profile>(profile_->GetOriginalProfile()), + content::NotificationService::NoDetails()); + } -void BookmarkBubbleView::ViewHierarchyChanged(bool is_add, - views::View* parent, - views::View* child) { - if (is_add && child == this) - Init(); -} +bool BookmarkBubbleView::AcceleratorPressed( + const views::Accelerator& accelerator) { + if (accelerator.key_code() == ui::VKEY_RETURN) { + if (edit_button_->HasFocus()) + HandleButtonPressed(edit_button_); + else + HandleButtonPressed(close_button_); + return true; + } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { + remove_bookmark_ = newly_bookmarked_; + apply_edits_ = false; + } -BookmarkBubbleView::BookmarkBubbleView(BubbleDelegate* delegate, - Profile* profile, - const GURL& url, - bool newly_bookmarked) - : delegate_(delegate), - profile_(profile), - url_(url), - newly_bookmarked_(newly_bookmarked), - parent_model_( - profile_->GetBookmarkModel(), - profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)), - remove_bookmark_(false), - apply_edits_(true) { + return BubbleDelegateView::AcceleratorPressed(accelerator); } void BookmarkBubbleView::Init() { remove_link_ = new views::Link(l10n_util::GetStringUTF16( IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); remove_link_->set_listener(this); - remove_link_->SetBackgroundColor(Bubble::kBackgroundColor); edit_button_ = new views::NativeTextButton( this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); @@ -189,7 +165,6 @@ void BookmarkBubbleView::Init() { views::Label* combobox_label = new views::Label( l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); - combobox_label->SetBackgroundColor(Bubble::kBackgroundColor); parent_combobox_ = new views::Combobox(&parent_model_); parent_combobox_->SetSelectedItem(parent_model_.node_parent_index()); @@ -202,7 +177,6 @@ void BookmarkBubbleView::Init() { IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); title_label->SetFont( ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); - title_label->SetBackgroundColor(Bubble::kBackgroundColor); title_label->SetEnabledColor(SkColorSetRGB(6, 45, 117)); GridLayout* layout = new GridLayout(this); @@ -245,7 +219,6 @@ void BookmarkBubbleView::Init() { layout->StartRow(0, 2); views::Label* label = new views::Label( l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); - label->SetBackgroundColor(Bubble::kBackgroundColor); layout->AddView(label); title_tf_ = new views::Textfield(); title_tf_->SetText(GetTitle()); @@ -261,6 +234,23 @@ void BookmarkBubbleView::Init() { layout->StartRow(0, 3); layout->AddView(edit_button_); layout->AddView(close_button_); + + AddAccelerator(views::Accelerator(ui::VKEY_RETURN, 0)); +} + +BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, + Profile* profile, + const GURL& url, + bool newly_bookmarked) + : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT, kColor), + profile_(profile), + url_(url), + newly_bookmarked_(newly_bookmarked), + parent_model_( + profile_->GetBookmarkModel(), + profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url)), + remove_bookmark_(false), + apply_edits_(true) { } string16 BookmarkBubbleView::GetTitle() { @@ -286,9 +276,7 @@ void BookmarkBubbleView::LinkClicked(views::Link* source, int event_flags) { // Set this so we remove the bookmark after the window closes. remove_bookmark_ = true; apply_edits_ = false; - - bubble_->set_fade_away_on_close(true); - Close(); + StartFade(false); } void BookmarkBubbleView::ItemChanged(views::Combobox* combobox, @@ -297,97 +285,32 @@ void BookmarkBubbleView::ItemChanged(views::Combobox* combobox, if (new_index + 1 == parent_model_.GetItemCount()) { UserMetrics::RecordAction( UserMetricsAction("BookmarkBubble_EditFromCombobox")); - ShowEditor(); - return; } } -void BookmarkBubbleView::BubbleClosing(Bubble* bubble, - bool closed_by_escape) { - if (closed_by_escape) { - remove_bookmark_ = newly_bookmarked_; - apply_edits_ = false; - } - - // We have to reset |bubble_| here, not in our destructor, because we'll be - // destroyed asynchronously and the shown state will be checked before then. - DCHECK(bookmark_bubble_ == this); - bookmark_bubble_ = NULL; - - if (delegate_) - delegate_->BubbleClosing(bubble, closed_by_escape); - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_BOOKMARK_BUBBLE_HIDDEN, - content::Source<Profile>(profile_->GetOriginalProfile()), - content::NotificationService::NoDetails()); -} - -bool BookmarkBubbleView::CloseOnEscape() { - return delegate_ ? delegate_->CloseOnEscape() : true; -} - -bool BookmarkBubbleView::FadeInOnShow() { - return false; -} - -string16 BookmarkBubbleView::GetAccessibleName() { - return l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_ADD_BOOKMARK); -} - -void BookmarkBubbleView::Close() { - ApplyEdits(); - GetWidget()->Close(); -} - void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { if (sender == edit_button_) { UserMetrics::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); - bubble_->set_fade_away_on_close(true); ShowEditor(); } else { - DCHECK(sender == close_button_); - bubble_->set_fade_away_on_close(true); - Close(); + DCHECK_EQ(sender, close_button_); + StartFade(false); } - // WARNING: we've most likely been deleted when CloseWindow returns. } void BookmarkBubbleView::ShowEditor() { const BookmarkNode* node = profile_->GetBookmarkModel()->GetMostRecentlyAddedNodeForURL(url_); + views::Widget* parent = anchor_view()->GetWidget(); + Profile* profile = profile_; + ApplyEdits(); + GetWidget()->Close(); -#if defined(USE_AURA) - NOTIMPLEMENTED(); - gfx::NativeView parent = NULL; -#elif defined(OS_WIN) - // Parent the editor to our root ancestor (not the root we're in, as that - // is the info bubble and will close shortly). - HWND parent = GetAncestor(GetWidget()->GetNativeView(), GA_ROOTOWNER); - - // We're about to show the bookmark editor. When the bookmark editor closes - // we want the browser to become active. NativeWidgetWin::Hide() does a hide - // in a such way that activation isn't changed, which means when we close - // Windows gets confused as to who it should give active status to. We - // explicitly hide the bookmark bubble window in such a way that activation - // status changes. That way, when the editor closes, activation is properly - // restored to the browser. - ShowWindow(GetWidget()->GetNativeView(), SW_HIDE); -#elif defined(TOOLKIT_USES_GTK) - gfx::NativeWindow parent = GTK_WINDOW( - static_cast<views::NativeWidgetGtk*>(GetWidget()->native_widget())-> - GetTransientParent()); -#endif - - // Even though we just hid the window, we need to invoke Close to schedule - // the delete and all that. - Close(); - - if (node) { - BookmarkEditor::Show(parent, profile_, + if (node) + BookmarkEditor::Show(parent->GetNativeWindow(), profile, BookmarkEditor::EditDetails::EditNode(node), BookmarkEditor::SHOW_TREE); - } } void BookmarkBubbleView::ApplyEdits() { @@ -404,8 +327,7 @@ void BookmarkBubbleView::ApplyEdits() { UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); } // Last index means 'Choose another folder...' - if (parent_combobox_->selected_item() < - parent_model_.GetItemCount() - 1) { + if (parent_combobox_->selected_item() < parent_model_.GetItemCount() - 1) { const BookmarkNode* new_parent = parent_model_.GetNodeAt(parent_combobox_->selected_item()); if (new_parent != node->parent()) { diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h index 38c15e2..c134802 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h @@ -8,19 +8,14 @@ #include "base/string16.h" #include "chrome/browser/bookmarks/recently_used_folders_combo_model.h" -#include "chrome/browser/ui/views/bubble/bubble.h" #include "googleurl/src/gurl.h" -#include "ui/gfx/rect.h" +#include "views/bubble/bubble_delegate.h" #include "views/controls/button/button.h" #include "views/controls/combobox/combobox.h" #include "views/controls/link_listener.h" -#include "views/view.h" class Profile; -class BookmarkModel; -class BookmarkNode; - namespace views { class TextButton; class Textfield; @@ -30,18 +25,15 @@ class Textfield; // Bubble. BookmarkBubbleView provides views for unstarring and editing the // bookmark it is created with. Don't create a BookmarkBubbleView directly, // instead use the static Show method. -class BookmarkBubbleView : public views::View, +class BookmarkBubbleView : public views::BubbleDelegateView, public views::LinkListener, public views::ButtonListener, - public views::Combobox::Listener, - public BubbleDelegate { + public views::Combobox::Listener { public: - static void Show(views::Widget* widget, - const gfx::Rect& bounds, - BubbleDelegate* delegate, - Profile* profile, - const GURL& url, - bool newly_bookmarked); + static void ShowBubble(views::View* anchor_view, + Profile* profile, + const GURL& url, + bool newly_bookmarked); static bool IsShowing(); @@ -49,25 +41,27 @@ class BookmarkBubbleView : public views::View, virtual ~BookmarkBubbleView(); - void set_bubble(Bubble* bubble) { bubble_ = bubble; } + // views::BubbleDelegateView methods. + virtual views::View* GetInitiallyFocusedView() OVERRIDE; + virtual gfx::Point GetAnchorPoint() OVERRIDE; + + // views::WidgetDelegate method. + virtual void WindowClosing() OVERRIDE; - // Override to close on return. + // views::View method. virtual bool AcceleratorPressed( const views::Accelerator& accelerator) OVERRIDE; - virtual void ViewHierarchyChanged( - bool is_add, View* parent, View* child) OVERRIDE; + protected: + // views::BubbleDelegateView method. + virtual void Init() OVERRIDE; private: // Creates a BookmarkBubbleView. - // |title| is the title of the page. If newly_bookmarked is false, title is - // ignored and the title of the bookmark is fetched from the database. - BookmarkBubbleView(BubbleDelegate* delegate, + BookmarkBubbleView(views::View* anchor_view, Profile* profile, const GURL& url, bool newly_bookmarked); - // Creates the child views. - void Init(); // Returns the title to display. string16 GetTitle(); @@ -85,17 +79,6 @@ class BookmarkBubbleView : public views::View, int prev_index, int new_index) OVERRIDE; - // BubbleDelegate methods. These forward to the BubbleDelegate supplied in the - // constructor as well as sending out the necessary notification. - virtual void BubbleShown() OVERRIDE; - virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; - virtual bool CloseOnEscape() OVERRIDE; - virtual bool FadeInOnShow() OVERRIDE; - virtual string16 GetAccessibleName() OVERRIDE; - - // Closes the bubble. - void Close(); - // Handle the message when the user presses a button. void HandleButtonPressed(views::Button* sender); @@ -108,12 +91,6 @@ class BookmarkBubbleView : public views::View, // The bookmark bubble, if we're showing one. static BookmarkBubbleView* bookmark_bubble_; - // The Bubble showing us. - Bubble* bubble_; - - // Delegate for the bubble, may be null. - BubbleDelegate* delegate_; - // The profile. Profile* profile_; diff --git a/chrome/browser/ui/views/browser_dialogs.h b/chrome/browser/ui/views/browser_dialogs.h index f0f0026..2d3492c 100644 --- a/chrome/browser/ui/views/browser_dialogs.h +++ b/chrome/browser/ui/views/browser_dialogs.h @@ -22,27 +22,24 @@ class EditSearchEngineControllerDelegate; class Extension; class FindBar; class GURL; -class BubbleDelegate; class Profile; class TabContents; class TabContentsWrapper; class TemplateURL; namespace gfx { -class Rect; class Size; } namespace views { +class View; class Widget; } namespace browser { // Shows or hides the global bookmark bubble for the star button. -void ShowBookmarkBubbleView(views::Widget* parent, - const gfx::Rect& bounds, - BubbleDelegate* delegate, +void ShowBookmarkBubbleView(views::View* anchor_view, Profile* profile, const GURL& url, bool newly_bookmarked); diff --git a/chrome/browser/ui/views/critical_notification_bubble_view.cc b/chrome/browser/ui/views/critical_notification_bubble_view.cc index 63f00c2..ca95103 100644 --- a/chrome/browser/ui/views/critical_notification_bubble_view.cc +++ b/chrome/browser/ui/views/critical_notification_bubble_view.cc @@ -47,8 +47,8 @@ const int kRefreshBubbleEvery = 1000; // Millisecond. // CriticalNotificationBubbleView CriticalNotificationBubbleView::CriticalNotificationBubbleView( - const gfx::Point& anchor_point) - : BubbleDelegateView(anchor_point, + views::View* anchor_view) + : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT, SK_ColorWHITE) { set_close_on_deactivate(false); diff --git a/chrome/browser/ui/views/critical_notification_bubble_view.h b/chrome/browser/ui/views/critical_notification_bubble_view.h index 79c9826..0e886a8 100644 --- a/chrome/browser/ui/views/critical_notification_bubble_view.h +++ b/chrome/browser/ui/views/critical_notification_bubble_view.h @@ -18,7 +18,7 @@ class NativeTextButton; class CriticalNotificationBubbleView : public views::BubbleDelegateView, public views::ButtonListener { public: - explicit CriticalNotificationBubbleView(const gfx::Point& anchor_point); + explicit CriticalNotificationBubbleView(views::View* anchor_view); virtual ~CriticalNotificationBubbleView(); // views::ButtonListener overrides: diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 4856ab5..4cdc1c2 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -56,7 +56,6 @@ #include "ui/gfx/color_utils.h" #include "ui/gfx/image/image.h" #include "ui/gfx/skia_util.h" -#include "views/bubble/bubble_border.h" #include "views/controls/label.h" #include "views/controls/textfield/native_textfield_views.h" #include "views/drag_utils.h" @@ -395,14 +394,8 @@ void LocationBarView::SetStarToggled(bool on) { } void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { - gfx::Rect screen_bounds(star_view_->GetImageBounds()); - // Compensate for some built-in padding in the Star image. - screen_bounds.Inset(1, 1, 1, 2); - gfx::Point origin(screen_bounds.origin()); - views::View::ConvertPointToScreen(star_view_, &origin); - screen_bounds.set_origin(origin); - browser::ShowBookmarkBubbleView(GetWidget(), screen_bounds, star_view_, - browser_->profile(), url, newly_bookmarked); + browser::ShowBookmarkBubbleView(star_view_, browser_->profile(), url, + newly_bookmarked); } gfx::Point LocationBarView::GetLocationEntryOrigin() const { diff --git a/chrome/browser/ui/views/location_bar/star_view.cc b/chrome/browser/ui/views/location_bar/star_view.cc index 6a0cd14..75a3b15 100644 --- a/chrome/browser/ui/views/location_bar/star_view.cc +++ b/chrome/browser/ui/views/location_bar/star_view.cc @@ -65,14 +65,3 @@ bool StarView::OnKeyPressed(const views::KeyEvent& event) { } return false; } - -void StarView::BubbleClosing(Bubble* bubble, bool closed_by_escape) { -} - -bool StarView::CloseOnEscape() { - return true; -} - -bool StarView::FadeInOnShow() { - return false; -} diff --git a/chrome/browser/ui/views/location_bar/star_view.h b/chrome/browser/ui/views/location_bar/star_view.h index eacf925..7125287 100644 --- a/chrome/browser/ui/views/location_bar/star_view.h +++ b/chrome/browser/ui/views/location_bar/star_view.h @@ -6,18 +6,16 @@ #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_STAR_VIEW_H_ #pragma once -#include "chrome/browser/ui/views/bubble/bubble.h" #include "views/controls/image_view.h" class CommandUpdater; -class Bubble; namespace views { class KeyEvent; class MouseEvent; } -class StarView : public views::ImageView, public BubbleDelegate { +class StarView : public views::ImageView { public: explicit StarView(CommandUpdater* command_updater); virtual ~StarView(); @@ -34,11 +32,6 @@ class StarView : public views::ImageView, public BubbleDelegate { virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; - // BubbleDelegate overrides: - virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; - virtual bool CloseOnEscape() OVERRIDE; - virtual bool FadeInOnShow() OVERRIDE; - // The CommandUpdater for the Browser object that owns the location bar. CommandUpdater* command_updater_; diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc index 6da0619..79f226a 100644 --- a/chrome/browser/ui/views/toolbar_view.cc +++ b/chrome/browser/ui/views/toolbar_view.cc @@ -729,12 +729,9 @@ void ToolbarView::LoadImages() { void ToolbarView::ShowCriticalNotification() { #if defined(OS_WIN) - gfx::Point screen_loc(app_menu_->width() / 2, app_menu_->height()); - views::View::ConvertPointToScreen(app_menu_, &screen_loc); - CriticalNotificationBubbleView* bubble_delegate = - new CriticalNotificationBubbleView(screen_loc); - views::BubbleDelegateView::CreateBubble(bubble_delegate, GetWidget()); + new CriticalNotificationBubbleView(app_menu_); + views::BubbleDelegateView::CreateBubble(bubble_delegate); bubble_delegate->StartFade(true); #endif } diff --git a/ui/aura_shell/examples/bubble.cc b/ui/aura_shell/examples/bubble.cc index 210b3f8..ff0e7a1 100644 --- a/ui/aura_shell/examples/bubble.cc +++ b/ui/aura_shell/examples/bubble.cc @@ -15,20 +15,19 @@ namespace examples { struct BubbleConfig { string16 label; SkColor color; - gfx::Point anchor_point; + views::View* anchor_view; views::BubbleBorder::ArrowLocation arrow; }; class ExampleBubbleDelegateView : public views::BubbleDelegateView { public: ExampleBubbleDelegateView(const BubbleConfig& config) - : BubbleDelegateView(config.anchor_point, config.arrow, config.color), + : BubbleDelegateView(config.anchor_view, config.arrow, config.color), label_(config.label) {} virtual void Init() OVERRIDE { SetLayoutManager(new views::FillLayout()); views::Label* label = new views::Label(label_); - label->set_border(views::Border::CreateSolidBorder(10, GetColor())); AddChildView(label); } @@ -36,14 +35,14 @@ class ExampleBubbleDelegateView : public views::BubbleDelegateView { string16 label_; }; -void CreatePointyBubble(views::Widget* parent, const gfx::Point& origin) { +void CreatePointyBubble(views::View* anchor_view) { BubbleConfig config; config.label = ASCIIToUTF16("PointyBubble"); config.color = SK_ColorWHITE; - config.anchor_point = origin; + config.anchor_view = anchor_view; config.arrow = views::BubbleBorder::TOP_LEFT; - views::Widget* bubble = views::BubbleDelegateView::CreateBubble( - new ExampleBubbleDelegateView(config), parent); + ExampleBubbleDelegateView* bubble = new ExampleBubbleDelegateView(config); + views::BubbleDelegateView::CreateBubble(bubble); bubble->Show(); } diff --git a/ui/aura_shell/examples/example_factory.h b/ui/aura_shell/examples/example_factory.h index da60715..8e18419 100644 --- a/ui/aura_shell/examples/example_factory.h +++ b/ui/aura_shell/examples/example_factory.h @@ -8,18 +8,14 @@ #include "ui/gfx/native_widget_types.h" -namespace gfx { -class Point; -} - namespace views { -class Widget; +class View; } namespace aura_shell { namespace examples { -void CreatePointyBubble(views::Widget* parent, const gfx::Point& origin); +void CreatePointyBubble(views::View* anchor_view); void CreateLock(); @@ -29,5 +25,4 @@ void CreateWidgetsWindow(); } // namespace examples } // namespace aura_shell - #endif // UI_AURA_SHELL_SHELL_FACTORY_H_ diff --git a/ui/aura_shell/examples/window_type_launcher.cc b/ui/aura_shell/examples/window_type_launcher.cc index 2b9312a..37cc500 100644 --- a/ui/aura_shell/examples/window_type_launcher.cc +++ b/ui/aura_shell/examples/window_type_launcher.cc @@ -124,9 +124,7 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender, } else if (sender == create_nonresizable_button_) { ToplevelWindow::CreateToplevelWindow(ToplevelWindow::CreateParams()); } else if (sender == bubble_button_) { - gfx::Point origin = bubble_button_->bounds().origin(); - views::View::ConvertPointToScreen(bubble_button_->parent(), &origin); - CreatePointyBubble(GetWidget(), origin); + CreatePointyBubble(sender); } else if (sender == lock_button_) { CreateLock(); } else if (sender == widgets_button_) { diff --git a/views/bubble/bubble_delegate.cc b/views/bubble/bubble_delegate.cc index c5b27ee..9f99747 100644 --- a/views/bubble/bubble_delegate.cc +++ b/views/bubble/bubble_delegate.cc @@ -77,6 +77,7 @@ BubbleDelegateView::BubbleDelegateView() : close_on_esc_(true), close_on_deactivate_(true), allow_bubble_offscreen_(false), + anchor_view_(NULL), arrow_location_(BubbleBorder::TOP_LEFT), color_(SK_ColorWHITE), border_widget_(NULL), @@ -86,13 +87,13 @@ BubbleDelegateView::BubbleDelegateView() } BubbleDelegateView::BubbleDelegateView( - const gfx::Point& anchor_point, + View* anchor_view, BubbleBorder::ArrowLocation arrow_location, const SkColor& color) : close_on_esc_(true), close_on_deactivate_(true), allow_bubble_offscreen_(false), - anchor_point_(anchor_point), + anchor_view_(anchor_view), arrow_location_(arrow_location), color_(color), original_opacity_(255), @@ -108,14 +109,16 @@ BubbleDelegateView::~BubbleDelegateView() { } // static -Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate, - Widget* parent_widget) { +Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) { bubble_delegate->Init(); + Widget* parent_widget = bubble_delegate->anchor_view() ? + bubble_delegate->anchor_view()->GetWidget() : NULL; Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent_widget); #if defined(OS_WIN) && !defined(USE_AURA) - bubble_delegate->InitializeBorderWidget(parent_widget); + // First set the contents view to initialize view bounds for widget sizing. bubble_widget->SetContentsView(bubble_delegate->GetContentsView()); + bubble_delegate->InitializeBorderWidget(parent_widget); bubble_widget->SetBounds(bubble_delegate->GetBubbleClientBounds()); #else bubble_widget->SetBounds(bubble_delegate->GetBubbleBounds()); @@ -155,7 +158,22 @@ void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, } gfx::Point BubbleDelegateView::GetAnchorPoint() { - return anchor_point_; + if (!anchor_view()) + return gfx::Point(); + + BubbleBorder::ArrowLocation location = GetArrowLocation(); + gfx::Point anchor(anchor_view()->bounds().CenterPoint()); + // By default, pick the middle of |anchor_view_|'s edge opposite the arrow. + if (BubbleBorder::is_arrow_on_horizontal(location)) { + anchor.SetPoint(anchor_view()->width() / 2, + BubbleBorder::is_arrow_on_top(location) ? anchor_view()->height() : 0); + } else if (BubbleBorder::has_arrow(location)) { + anchor.SetPoint( + BubbleBorder::is_arrow_on_left(location) ? anchor_view()->width() : 0, + anchor_view_->height() / 2); + } + View::ConvertPointToScreen(anchor_view(), &anchor); + return anchor; } BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { diff --git a/views/bubble/bubble_delegate.h b/views/bubble/bubble_delegate.h index 13da32f..be02e44 100644 --- a/views/bubble/bubble_delegate.h +++ b/views/bubble/bubble_delegate.h @@ -29,14 +29,13 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, public Widget::Observer { public: BubbleDelegateView(); - BubbleDelegateView(const gfx::Point& anchor_point, + BubbleDelegateView(View* anchor_view, BubbleBorder::ArrowLocation arrow_location, const SkColor& color); virtual ~BubbleDelegateView(); // Create and initialize the bubble Widget(s) with proper bounds. - static Widget* CreateBubble(BubbleDelegateView* bubble_delegate, - Widget* parent_widget); + static Widget* CreateBubble(BubbleDelegateView* bubble_delegate); // WidgetDelegate overrides: virtual View* GetInitiallyFocusedView() OVERRIDE; @@ -60,6 +59,8 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, allow_bubble_offscreen_ = allow_bubble_offscreen; } + View* anchor_view() const { return anchor_view_; } + bool use_focusless() const { return use_focusless_; } void set_use_focusless(bool use_focusless) { use_focusless_ = use_focusless; @@ -124,8 +125,8 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, // re-positioning should be performed. bool allow_bubble_offscreen_; - // The screen point where this bubble's arrow is anchored. - gfx::Point anchor_point_; + // The view hosting this bubble; the arrow is anchored to this view. + View* anchor_view_; // The arrow's location on the bubble. BubbleBorder::ArrowLocation arrow_location_; diff --git a/views/bubble/bubble_delegate_unittest.cc b/views/bubble/bubble_delegate_unittest.cc index 5c94b75..4064700 100644 --- a/views/bubble/bubble_delegate_unittest.cc +++ b/views/bubble/bubble_delegate_unittest.cc @@ -13,9 +13,9 @@ typedef ViewsTestBase BubbleDelegateTest; TEST_F(BubbleDelegateTest, CreateDelegate) { BubbleDelegateView* bubble_delegate = new BubbleDelegateView( - gfx::Point(100, 100), BubbleBorder::LEFT_TOP, SK_ColorGREEN); + NULL, BubbleBorder::NONE, SK_ColorGREEN); scoped_ptr<Widget> bubble_widget( - BubbleDelegateView::CreateBubble(bubble_delegate, NULL)); + BubbleDelegateView::CreateBubble(bubble_delegate)); EXPECT_EQ(bubble_delegate, bubble_widget->widget_delegate()); EXPECT_EQ(bubble_widget, bubble_delegate->GetWidget()); diff --git a/views/bubble/bubble_frame_view_unittest.cc b/views/bubble/bubble_frame_view_unittest.cc index 3377e0b..5a1619c 100644 --- a/views/bubble/bubble_frame_view_unittest.cc +++ b/views/bubble/bubble_frame_view_unittest.cc @@ -14,7 +14,7 @@ namespace views { typedef ViewsTestBase BubbleFrameViewBasicTest; -const BubbleBorder::ArrowLocation kArrow = BubbleBorder::LEFT_BOTTOM; +const BubbleBorder::ArrowLocation kArrow = BubbleBorder::TOP_LEFT; const gfx::Rect kRect(10, 10, 200, 200); const SkColor kBackgroundColor = SK_ColorRED; const bool kAllowBubbleOffscreen = true; @@ -54,7 +54,7 @@ gfx::Size SizedBubbleDelegateView::GetPreferredSize() { return kRect.size(); } TEST_F(BubbleFrameViewBasicTest, NonClientHitTest) { BubbleDelegateView* delegate = new SizedBubbleDelegateView(); - scoped_ptr<Widget> widget(BubbleDelegateView::CreateBubble(delegate, NULL)); + scoped_ptr<Widget> widget(BubbleDelegateView::CreateBubble(delegate)); delegate->Show(); gfx::Point kPtInBound(100, 100); gfx::Point kPtOutsideBound(1000, 1000); diff --git a/views/examples/bubble_example.cc b/views/examples/bubble_example.cc index d7011a1..a5466c5 100644 --- a/views/examples/bubble_example.cc +++ b/views/examples/bubble_example.cc @@ -17,7 +17,7 @@ namespace examples { struct BubbleConfig { string16 label; SkColor color; - gfx::Point anchor_point; + views::View* anchor_view; views::BubbleBorder::ArrowLocation arrow; bool fade_in; bool fade_out; @@ -25,19 +25,19 @@ struct BubbleConfig { // Create four types of bubbles, one without arrow, one with an arrow, one // that fades in, and another that fades out and won't close on the escape key. -BubbleConfig kRoundConfig = { ASCIIToUTF16("RoundBubble"), 0xFFC1B1E1, - gfx::Point(), views::BubbleBorder::NONE, false, false }; -BubbleConfig kArrowConfig = { ASCIIToUTF16("ArrowBubble"), SK_ColorGRAY, - gfx::Point(), views::BubbleBorder::TOP_LEFT, false, false }; -BubbleConfig kFadeInConfig = { ASCIIToUTF16("FadeInBubble"), SK_ColorYELLOW, - gfx::Point(), views::BubbleBorder::BOTTOM_RIGHT, true, false }; -BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOutBubble"), SK_ColorWHITE, - gfx::Point(), views::BubbleBorder::BOTTOM_RIGHT, false, true }; +BubbleConfig kRoundConfig = { ASCIIToUTF16("Round"), 0xFFC1B1E1, NULL, + views::BubbleBorder::NONE, false, false }; +BubbleConfig kArrowConfig = { ASCIIToUTF16("Arrow"), SK_ColorGRAY, NULL, + views::BubbleBorder::TOP_LEFT, false, false }; +BubbleConfig kFadeInConfig = { ASCIIToUTF16("FadeIn"), SK_ColorYELLOW, NULL, + views::BubbleBorder::BOTTOM_RIGHT, true, false }; +BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOut"), SK_ColorWHITE, NULL, + views::BubbleBorder::LEFT_TOP, false, true }; class ExampleBubbleDelegateView : public views::BubbleDelegateView { public: ExampleBubbleDelegateView(const BubbleConfig& config) - : BubbleDelegateView(config.anchor_point, config.arrow, config.color), + : BubbleDelegateView(config.anchor_view, config.arrow, config.color), label_(config.label) {} protected: @@ -81,14 +81,10 @@ void BubbleExample::ButtonPressed(views::Button* sender, else if (sender == fade_out_) config = kFadeOutConfig; - config.anchor_point.set_x(sender->width() / 2); - config.anchor_point.set_y(sender->height() / 2); - views::View::ConvertPointToScreen(sender, &config.anchor_point); - + config.anchor_view = sender; ExampleBubbleDelegateView* bubble_delegate = new ExampleBubbleDelegateView(config); - views::BubbleDelegateView::CreateBubble(bubble_delegate, - example_view()->GetWidget()); + views::BubbleDelegateView::CreateBubble(bubble_delegate); if (config.fade_in) bubble_delegate->StartFade(true); |