Commit 32d9e1f2 authored by msw@chromium.org's avatar msw@chromium.org

Avoid overriding Bubble's GetAnchorRect() where possible.

Use the new BubbleDelegateView::set_anchor_insets() instead.
Remove redundant DCHECK, fix indent, revise comments.

BUG=none
TEST=No noticable changes (placement or otherwise).

Review URL: https://chromiumcodereview.appspot.com/10830366

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152375 0039d316-1c4b-4281-b951-d872f2087c98
parent 2a074bab
......@@ -121,13 +121,6 @@ views::View* BookmarkBubbleView::GetInitiallyFocusedView() {
return title_tf_;
}
gfx::Rect BookmarkBubbleView::GetAnchorRect() {
// Compensate for some built-in padding in the star image.
gfx::Rect rect(BubbleDelegateView::GetAnchorRect());
rect.Inset(0, anchor_view() ? 5 : 0);
return rect;
}
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.
......@@ -262,6 +255,8 @@ BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view,
parent_combobox_(NULL),
remove_bookmark_(false),
apply_edits_(true) {
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(gfx::Insets(5, 0, 5, 0));
}
string16 BookmarkBubbleView::GetTitle() {
......
......@@ -42,9 +42,8 @@ class BookmarkBubbleView : public views::BubbleDelegateView,
virtual ~BookmarkBubbleView();
// views::BubbleDelegateView methods.
// views::BubbleDelegateView method.
virtual views::View* GetInitiallyFocusedView() OVERRIDE;
virtual gfx::Rect GetAnchorRect() OVERRIDE;
// views::WidgetDelegate method.
virtual void WindowClosing() OVERRIDE;
......
......@@ -128,13 +128,6 @@ views::View* ChromeToMobileBubbleView::GetInitiallyFocusedView() {
return send_;
}
gfx::Rect ChromeToMobileBubbleView::GetAnchorRect() {
// Compensate for some built-in padding in the page action icon image.
gfx::Rect rect(BubbleDelegateView::GetAnchorRect());
rect.Inset(0, anchor_view() ? 5 : 0);
return rect;
}
void ChromeToMobileBubbleView::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.
......@@ -331,6 +324,9 @@ ChromeToMobileBubbleView::ChromeToMobileBubbleView(views::View* anchor_view,
send_copy_(NULL),
send_(NULL),
cancel_(NULL) {
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(gfx::Insets(5, 0, 5, 0));
// Generate the MHTML snapshot now to report its size in the bubble.
service_->GenerateSnapshot(browser_, weak_ptr_factory_.GetWeakPtr());
......
......@@ -46,7 +46,6 @@ class ChromeToMobileBubbleView : public views::BubbleDelegateView,
// views::BubbleDelegateView methods.
virtual views::View* GetInitiallyFocusedView() OVERRIDE;
virtual gfx::Rect GetAnchorRect() OVERRIDE;
virtual void WindowClosing() OVERRIDE;
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
......
......@@ -108,6 +108,9 @@ ContentSettingBubbleContents::ContentSettingBubbleContents(
custom_link_(NULL),
manage_link_(NULL),
close_button_(NULL) {
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(gfx::Insets(5, 0, 5, 0));
registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<WebContents>(web_contents));
}
......@@ -125,12 +128,6 @@ gfx::Size ContentSettingBubbleContents::GetPreferredSize() {
return preferred_size;
}
gfx::Rect ContentSettingBubbleContents::GetAnchorRect() {
gfx::Rect rect(BubbleDelegateView::GetAnchorRect());
rect.Inset(0, anchor_view() ? 5 : 0);
return rect;
}
void ContentSettingBubbleContents::Init() {
using views::GridLayout;
......
......@@ -53,9 +53,6 @@ class ContentSettingBubbleContents : public views::BubbleDelegateView,
virtual gfx::Size GetPreferredSize() OVERRIDE;
// views::BubbleDelegateView:
virtual gfx::Rect GetAnchorRect() OVERRIDE;
protected:
// views::BubbleDelegateView:
virtual void Init() OVERRIDE;
......
......@@ -78,16 +78,12 @@ void FirstRunBubble::Init() {
layout->AddView(subtext, columns->num_columns(), 1);
}
gfx::Rect FirstRunBubble::GetAnchorRect() {
// Compensate for padding in anchor.
gfx::Rect rect(BubbleDelegateView::GetAnchorRect());
rect.Inset(0, anchor_view() ? kAnchorVerticalInset : 0);
return rect;
}
FirstRunBubble::FirstRunBubble(Browser* browser, views::View* anchor_view)
: views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
browser_(browser) {
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(
gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0));
}
FirstRunBubble::~FirstRunBubble() {
......
......@@ -16,9 +16,6 @@ class FirstRunBubble : public views::BubbleDelegateView,
// |browser| is the opening browser and is NULL in unittests.
static FirstRunBubble* ShowBubble(Browser* browser, views::View* anchor_view);
// views::BubbleDelegateView overrides:
virtual gfx::Rect GetAnchorRect() OVERRIDE;
protected:
// views::BubbleDelegateView overrides:
virtual void Init() OVERRIDE;
......
......@@ -65,7 +65,10 @@ GlobalErrorBubbleView::GlobalErrorBubbleView(
: BubbleDelegateView(anchor_view, location),
browser_(browser),
error_(error) {
DCHECK(error_);
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(
gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
int resource_id = error_->GetBubbleViewIconResourceID();
scoped_ptr<views::ImageView> image_view(new views::ImageView());
......@@ -145,12 +148,6 @@ GlobalErrorBubbleView::GlobalErrorBubbleView(
GlobalErrorBubbleView::~GlobalErrorBubbleView() {
}
gfx::Rect GlobalErrorBubbleView::GetAnchorRect() {
gfx::Rect rect(views::BubbleDelegateView::GetAnchorRect());
rect.Inset(0, anchor_view() ? kAnchorVerticalInset : 0);
return rect;
}
void GlobalErrorBubbleView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (error_) {
......
......@@ -23,9 +23,6 @@ class GlobalErrorBubbleView : public views::ButtonListener,
const base::WeakPtr<GlobalError>& error);
virtual ~GlobalErrorBubbleView();
// views::BubbleDelegateView implementation.
virtual gfx::Rect GetAnchorRect() OVERRIDE;
// views::ButtonListener implementation.
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
......
......@@ -74,6 +74,8 @@ ZoomBubbleView::ZoomBubbleView(views::View* anchor_view,
label_(NULL),
tab_contents_(tab_contents),
auto_close_(auto_close) {
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(gfx::Insets(5, 0, 5, 0));
set_use_focusless(auto_close);
set_notify_enter_exit_on_child(true);
}
......@@ -147,13 +149,6 @@ void ZoomBubbleView::Init() {
StartTimerIfNecessary();
}
gfx::Rect ZoomBubbleView::GetAnchorRect() {
// Compensate for some built-in padding in the zoom image.
gfx::Rect rect(BubbleDelegateView::GetAnchorRect());
rect.Inset(0, anchor_view() ? 5 : 0);
return rect;
}
void ZoomBubbleView::WindowClosing() {
DCHECK(zoom_bubble_ == this);
zoom_bubble_ = NULL;
......
......@@ -54,7 +54,6 @@ class ZoomBubbleView : public views::BubbleDelegateView,
// views::BubbleDelegateView method.
virtual void Init() OVERRIDE;
virtual gfx::Rect GetAnchorRect() OVERRIDE;
virtual void WindowClosing() OVERRIDE;
// Singleton instance of the zoom bubble. The zoom bubble can only be shown on
......
......@@ -60,6 +60,9 @@ NetworkProfileBubbleView::NetworkProfileBubbleView(
: BubbleDelegateView(anchor, views::BubbleBorder::TOP_RIGHT),
navigator_(navigator),
profile_(profile) {
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(
gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0));
}
////////////////////////////////////////////////////////////////////////////////
......@@ -107,13 +110,6 @@ void NetworkProfileBubbleView::Init() {
layout->AddView(ok_button);
}
gfx::Rect NetworkProfileBubbleView::GetAnchorRect() {
// Compensate for padding in anchor.
gfx::Rect rect(BubbleDelegateView::GetAnchorRect());
rect.Inset(0, anchor_view() ? kAnchorVerticalInset : 0);
return rect;
}
void NetworkProfileBubbleView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
NetworkProfileBubble::RecordUmaEvent(
......
......@@ -29,7 +29,6 @@ class NetworkProfileBubbleView : public views::BubbleDelegateView,
// views::BubbleDelegateView:
virtual void Init() OVERRIDE;
virtual gfx::Rect GetAnchorRect() OVERRIDE;
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
......
......@@ -121,6 +121,9 @@ PageInfoBubbleView::PageInfoBubbleView(views::View* anchor_view,
animation_start_height_(0),
navigator_(navigator),
web_contents_(web_contents) {
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(gfx::Insets(5, 0, 5, 0));
if (cert_id_ > 0) {
scoped_refptr<net::X509Certificate> cert;
content::CertStore::GetInstance()->RetrieveCert(cert_id_, &cert);
......@@ -283,13 +286,6 @@ void PageInfoBubbleView::OnPageInfoModelChanged() {
resize_animation_.Show();
}
gfx::Rect PageInfoBubbleView::GetAnchorRect() {
// Compensate for some built-in padding in the icon.
gfx::Rect anchor(BubbleDelegateView::GetAnchorRect());
anchor.Inset(0, anchor_view() ? 5 : 0);
return anchor;
}
void PageInfoBubbleView::LinkClicked(views::Link* source, int event_flags) {
navigator_->OpenURL(OpenURLParams(GURL(chrome::kPageInfoHelpCenterURL),
Referrer(),
......
......@@ -39,9 +39,6 @@ class PageInfoBubbleView : public views::BubbleDelegateView,
// PageInfoModelObserver methods:
virtual void OnPageInfoModelChanged() OVERRIDE;
// views::BubbleDelegate methods:
virtual gfx::Rect GetAnchorRect() OVERRIDE;
// views::LinkListener methods:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
......
......@@ -71,12 +71,9 @@ const int kHeaderPaddingTop = 12;
// the popup header.
const int kHeaderRowSpacing = 4;
// In order to make the arrow of the bubble point directly at the location icon
// in the Omnibox rather then the bottom border of the Omnibox, the position of
// the bubble must be adjusted. This is the number of pixel the bubble must be
// moved towards the top of the screen (starting from the bottom border of the
// Omnibox).
const int kLocationIconBottomMargin = 5;
// To make the bubble's arrow point directly at the location icon rather than at
// the Omnibox's edge, inset the bubble's anchor rect by this amount of pixels.
const int kLocationIconVerticalMargin = 5;
// The margins between the popup border and the popup content.
const int kPopupMarginTop = 4;
......@@ -143,9 +140,6 @@ class InternalPageInfoPopupView : public views::BubbleDelegateView {
virtual ~InternalPageInfoPopupView();
private:
// views::BubbleDelegate implementations.
virtual gfx::Rect GetAnchorRect() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(InternalPageInfoPopupView);
};
......@@ -228,6 +222,10 @@ void PopupHeaderView::SetIdentityStatus(const string16& status,
InternalPageInfoPopupView::InternalPageInfoPopupView(views::View* anchor_view)
: BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT) {
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(gfx::Insets(kLocationIconVerticalMargin, 0,
kLocationIconVerticalMargin, 0));
const int kSpacing = 4;
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, kSpacing,
kSpacing, kSpacing));
......@@ -251,14 +249,6 @@ InternalPageInfoPopupView::InternalPageInfoPopupView(views::View* anchor_view)
InternalPageInfoPopupView::~InternalPageInfoPopupView() {
}
gfx::Rect InternalPageInfoPopupView::GetAnchorRect() {
// Compensate for some built-in padding in the icon. This will make the arrow
// point to the middle of the icon.
gfx::Rect anchor(BubbleDelegateView::GetAnchorRect());
anchor.Inset(0, anchor_view() ? kLocationIconBottomMargin : 0);
return anchor;
}
////////////////////////////////////////////////////////////////////////////////
// WebsiteSettingsPopupView
////////////////////////////////////////////////////////////////////////////////
......@@ -296,6 +286,10 @@ WebsiteSettingsPopupView::WebsiteSettingsPopupView(
cert_id_(0),
connection_info_content_(NULL),
page_info_content_(NULL) {
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_insets(gfx::Insets(kLocationIconVerticalMargin, 0,
kLocationIconVerticalMargin, 0));
views::GridLayout* layout = new views::GridLayout(this);
SetLayoutManager(layout);
const int content_column = 0;
......@@ -352,14 +346,6 @@ void WebsiteSettingsPopupView::OnPermissionChanged(
permission_selector->GetSelectedSetting());
}
gfx::Rect WebsiteSettingsPopupView::GetAnchorRect() {
// Compensate for some built-in padding in the icon. This will make the arrow
// point to the middle of the icon.
gfx::Rect anchor(BubbleDelegateView::GetAnchorRect());
anchor.Inset(0, anchor_view() ? kLocationIconBottomMargin : 0);
return anchor;
}
void WebsiteSettingsPopupView::OnWidgetClosing(views::Widget* widget) {
presenter_->OnUIClosing();
}
......
......@@ -60,8 +60,7 @@ class WebsiteSettingsPopupView
virtual void OnPermissionChanged(
PermissionSelectorView* selector) OVERRIDE;
// views::BubbleDelegate implementations.
virtual gfx::Rect GetAnchorRect() OVERRIDE;
// views::BubbleDelegate implementation.
virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE;
// views::ButtonListener implementation.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment