summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-17 00:48:32 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-17 00:48:32 +0000
commitafe4d90cf8229fa1e399091ea5d7eb39a9883133 (patch)
treeebb6d6aa83dc01219f4779cb32cd17bbe5a0df58
parent99d50d2d6435df256195c198f72d882ebf9e40f7 (diff)
downloadchromium_src-afe4d90cf8229fa1e399091ea5d7eb39a9883133.zip
chromium_src-afe4d90cf8229fa1e399091ea5d7eb39a9883133.tar.gz
chromium_src-afe4d90cf8229fa1e399091ea5d7eb39a9883133.tar.bz2
Rebase PageInfoBubble on the new views bubble.
Move ShowPageInfoBubble to browser_dialogs.h, nix page_info_window.h. Add BubbleDelegateView::SizeToContents(), slight refactoring. Add non-const location_icon_view(), make animation impls protected. BUG=97248,98312,98323 TEST=Page info bubble has the same behavior/appearance. Review URL: http://codereview.chromium.org/8508048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110403 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/external_tab_container_win.cc1
-rw-r--r--chrome/browser/ui/views/browser_dialogs.h10
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc4
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.h1
-rw-r--r--chrome/browser/ui/views/page_info_bubble_view.cc88
-rw-r--r--chrome/browser/ui/views/page_info_bubble_view.h28
-rw-r--r--chrome/browser/ui/views/page_info_window.h25
-rw-r--r--chrome/chrome_browser.gypi1
-rw-r--r--views/bubble/bubble_delegate.cc38
-rw-r--r--views/bubble/bubble_delegate.h15
10 files changed, 79 insertions, 132 deletions
diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc
index 9f7ea32..6a0cc75 100644
--- a/chrome/browser/external_tab_container_win.cc
+++ b/chrome/browser/external_tab_container_win.cc
@@ -28,7 +28,6 @@
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
-#include "chrome/browser/ui/views/page_info_bubble_view.h"
#include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h"
#include "chrome/browser/ui/views/tab_contents/tab_contents_container.h"
#include "chrome/common/automation_messages.h"
diff --git a/chrome/browser/ui/views/browser_dialogs.h b/chrome/browser/ui/views/browser_dialogs.h
index 2d3492c..af21b2c 100644
--- a/chrome/browser/ui/views/browser_dialogs.h
+++ b/chrome/browser/ui/views/browser_dialogs.h
@@ -8,6 +8,7 @@
#include <string>
+#include "content/browser/tab_contents/navigation_entry.h"
#include "ui/gfx/native_widget_types.h"
// This file contains functions for running a variety of browser dialogs and
@@ -38,7 +39,7 @@ class Widget;
namespace browser {
-// Shows or hides the global bookmark bubble for the star button.
+// Shows or hides the bookmark bubble anchored to the supplied view.
void ShowBookmarkBubbleView(views::View* anchor_view,
Profile* profile,
const GURL& url,
@@ -46,6 +47,13 @@ void ShowBookmarkBubbleView(views::View* anchor_view,
void HideBookmarkBubbleView();
bool IsBookmarkBubbleViewShowing();
+// Shows the page info bubble anchored to the supplied view.
+void ShowPageInfoBubble(views::View* anchor_view,
+ Profile* profile,
+ const GURL& url,
+ const NavigationEntry::SSLStatus& ssl,
+ bool show_history);
+
// Shows the about dialog. See AboutChromeView.
views::Widget* ShowAboutChromeView(gfx::NativeWindow parent,
Profile* profile);
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 1209ab2..8ed495b 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -59,7 +59,6 @@
#include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
#include "chrome/browser/ui/views/location_bar/location_icon_view.h"
-#include "chrome/browser/ui/views/page_info_window.h"
#include "chrome/browser/ui/views/status_bubble_views.h"
#include "chrome/browser/ui/views/tab_contents/tab_contents_container.h"
#include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
@@ -1142,7 +1141,8 @@ void BrowserView::ShowPageInfo(Profile* profile,
const GURL& url,
const NavigationEntry::SSLStatus& ssl,
bool show_history) {
- browser::ShowPageInfoBubble(this, profile, url, ssl, show_history);
+ browser::ShowPageInfoBubble(GetLocationBarView()->location_icon_view(),
+ profile, url, ssl, show_history);
}
void BrowserView::ShowAppMenu() {
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h
index 6ea8486..1f6a8e6 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.h
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.h
@@ -197,6 +197,7 @@ class LocationBarView : public LocationBar,
virtual void OnMouseCaptureLost() OVERRIDE;
#endif
+ LocationIconView* location_icon_view() { return location_icon_view_; }
const LocationIconView* location_icon_view() const {
return location_icon_view_;
}
diff --git a/chrome/browser/ui/views/page_info_bubble_view.cc b/chrome/browser/ui/views/page_info_bubble_view.cc
index 9a6dbed..b0bb3ae 100644
--- a/chrome/browser/ui/views/page_info_bubble_view.cc
+++ b/chrome/browser/ui/views/page_info_bubble_view.cc
@@ -30,6 +30,9 @@
namespace {
+// TODO(msw): Get color from theme/window color.
+const SkColor kColor = SK_ColorWHITE;
+
// Layout constants.
const int kHGapToBorder = 11;
const int kVerticalSectionPadding = 8;
@@ -98,22 +101,19 @@ class Section : public views::View,
////////////////////////////////////////////////////////////////////////////////
// PageInfoBubbleView
-Bubble* PageInfoBubbleView::bubble_ = NULL;
-
-PageInfoBubbleView::PageInfoBubbleView(gfx::NativeWindow parent_window,
+PageInfoBubbleView::PageInfoBubbleView(views::View* anchor_view,
Profile* profile,
const GURL& url,
const NavigationEntry::SSLStatus& ssl,
bool show_history)
- : ALLOW_THIS_IN_INITIALIZER_LIST(model_(profile, url, ssl,
+ : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT, kColor),
+ ALLOW_THIS_IN_INITIALIZER_LIST(model_(profile, url, ssl,
show_history, this)),
- parent_window_(parent_window),
cert_id_(ssl.cert_id()),
help_center_link_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(resize_animation_(this)),
animation_start_height_(0) {
- if (bubble_)
- bubble_->Close();
+
if (cert_id_ > 0) {
scoped_refptr<net::X509Certificate> cert;
CertStore::GetInstance()->RetrieveCert(cert_id_, &cert);
@@ -127,10 +127,13 @@ PageInfoBubbleView::PageInfoBubbleView(gfx::NativeWindow parent_window,
}
PageInfoBubbleView::~PageInfoBubbleView() {
+ resize_animation_.Reset();
}
void PageInfoBubbleView::ShowCertDialog() {
- ShowCertificateViewerByID(parent_window_, cert_id_);
+ gfx::NativeWindow parent =
+ anchor_view() ? anchor_view()->GetWidget()->GetNativeWindow() : NULL;
+ ShowCertificateViewerByID(parent, cert_id_);
}
gfx::Size PageInfoBubbleView::GetSeparatorSize() {
@@ -288,51 +291,42 @@ void PageInfoBubbleView::OnPageInfoModelChanged() {
// animation.
// TODO(derat): Remove this once we're not using a toplevel X window for the
// bubble.
- bubble_->SizeToContents();
+ SizeToContents();
#else
resize_animation_.SetSlideDuration(kPageInfoSlideDuration);
resize_animation_.Show();
#endif
}
-void PageInfoBubbleView::BubbleClosing(Bubble* bubble, bool closed_by_escape) {
- resize_animation_.Reset();
- bubble_ = NULL;
-}
-
-bool PageInfoBubbleView::CloseOnEscape() {
- return true;
-}
-
-bool PageInfoBubbleView::FadeInOnShow() {
- return false;
-}
-
-string16 PageInfoBubbleView::GetAccessibleName() {
- return ASCIIToUTF16("PageInfoBubble");
+gfx::Point PageInfoBubbleView::GetAnchorPoint() {
+ // Compensate for some built-in padding in the icon.
+ gfx::Point anchor(BubbleDelegateView::GetAnchorPoint());
+ return anchor_view() ? anchor.Subtract(gfx::Point(0, 5)) : anchor;
}
void PageInfoBubbleView::LinkClicked(views::Link* source, int event_flags) {
- // We want to make sure the info bubble closes once the link is activated. So
- // we close it explicitly rather than relying on a side-effect of opening a
- // new tab (see http://crosbug.com/10186).
- bubble_->Close();
-
GURL url = google_util::AppendGoogleLocaleParam(
GURL(chrome::kPageInfoHelpCenterURL));
Browser* browser = BrowserList::GetLastActive();
browser->OpenURL(
url, GURL(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK);
+ // NOTE: The bubble closes automatically on deactivation as the link opens.
}
void PageInfoBubbleView::AnimationEnded(const ui::Animation* animation) {
- LayoutSections();
- bubble_->SizeToContents();
+ if (animation == &resize_animation_) {
+ LayoutSections();
+ SizeToContents();
+ }
+ BubbleDelegateView::AnimationEnded(animation);
}
void PageInfoBubbleView::AnimationProgressed(const ui::Animation* animation) {
- LayoutSections();
- bubble_->SizeToContents();
+ if (animation == &resize_animation_) {
+ LayoutSections();
+ SizeToContents();
+ }
+ BubbleDelegateView::AnimationProgressed(animation);
}
////////////////////////////////////////////////////////////////////////////////
@@ -477,33 +471,15 @@ gfx::Size Section::LayoutItems(bool compute_bounds_only, int width) {
namespace browser {
-void ShowPageInfoBubble(BrowserView* browser_view,
+void ShowPageInfoBubble(views::View* anchor_view,
Profile* profile,
const GURL& url,
const NavigationEntry::SSLStatus& ssl,
bool show_history) {
- // Find where to point the bubble at.
- gfx::Point point;
- if (base::i18n::IsRTL()) {
- int width = browser_view->toolbar()->location_bar()->width();
- point = gfx::Point(width - kIconHorizontalOffset, 0);
- }
- point.Offset(0, kIconVerticalOffset);
- views::View::ConvertPointToScreen(browser_view->toolbar()->location_bar(),
- &point);
- gfx::Rect bounds = browser_view->toolbar()->location_bar()->bounds();
- bounds.set_origin(point);
- bounds.set_width(kIconHorizontalOffset);
-
- // Show the bubble. If the bubble already exist - it will be closed first.
PageInfoBubbleView* page_info_bubble =
- new PageInfoBubbleView(browser_view->GetNativeHandle(),
- profile, url, ssl, show_history);
- Bubble* bubble =
- Bubble::Show(browser_view->GetWidget(), bounds,
- views::BubbleBorder::TOP_LEFT,
- views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR,
- page_info_bubble, page_info_bubble);
- page_info_bubble->set_bubble(bubble);
+ new PageInfoBubbleView(anchor_view, profile, url, ssl, show_history);
+ views::BubbleDelegateView::CreateBubble(page_info_bubble);
+ page_info_bubble->Show();
}
+
}
diff --git a/chrome/browser/ui/views/page_info_bubble_view.h b/chrome/browser/ui/views/page_info_bubble_view.h
index 51f938c..5fad7ba 100644
--- a/chrome/browser/ui/views/page_info_bubble_view.h
+++ b/chrome/browser/ui/views/page_info_bubble_view.h
@@ -6,22 +6,17 @@
#define CHROME_BROWSER_UI_VIEWS_PAGE_INFO_BUBBLE_VIEW_H_
#pragma once
-#include "base/compiler_specific.h"
#include "chrome/browser/page_info_model.h"
#include "chrome/browser/page_info_model_observer.h"
-#include "chrome/browser/ui/views/bubble/bubble.h"
-#include "ui/base/animation/animation_delegate.h"
#include "ui/base/animation/slide_animation.h"
+#include "views/bubble/bubble_delegate.h"
#include "views/controls/link_listener.h"
-#include "views/view.h"
-class PageInfoBubbleView : public views::View,
+class PageInfoBubbleView : public views::BubbleDelegateView,
public PageInfoModelObserver,
- public BubbleDelegate,
- public views::LinkListener,
- public ui::AnimationDelegate {
+ public views::LinkListener {
public:
- PageInfoBubbleView(gfx::NativeWindow parent_window,
+ PageInfoBubbleView(views::View* anchor_view,
Profile* profile,
const GURL& url,
const NavigationEntry::SSLStatus& ssl,
@@ -31,19 +26,14 @@ class PageInfoBubbleView : public views::View,
// Show the certificate dialog.
void ShowCertDialog();
- void set_bubble(Bubble* bubble) { bubble_ = bubble; }
-
// views::View methods:
virtual gfx::Size GetPreferredSize();
// PageInfoModelObserver methods:
virtual void OnPageInfoModelChanged() OVERRIDE;
- // BubbleDelegate methods:
- virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE;
- virtual bool CloseOnEscape() OVERRIDE;
- virtual bool FadeInOnShow() OVERRIDE;
- virtual string16 GetAccessibleName() OVERRIDE;
+ // views::BubbleDelegate methods:
+ virtual gfx::Point GetAnchorPoint() OVERRIDE;
// views::LinkListener methods:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
@@ -65,15 +55,9 @@ class PageInfoBubbleView : public views::View,
// Layout the sections within the bubble.
void LayoutSections();
- // Global pointer to the bubble that is hosting our view.
- static Bubble* bubble_;
-
// The model providing the various section info.
PageInfoModel model_;
- // The parent window of the Bubble showing this view.
- gfx::NativeWindow parent_window_;
-
// The id of the certificate for this page.
int cert_id_;
diff --git a/chrome/browser/ui/views/page_info_window.h b/chrome/browser/ui/views/page_info_window.h
deleted file mode 100644
index 15881d7..0000000
--- a/chrome/browser/ui/views/page_info_window.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// 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.
-
-#ifndef CHROME_BROWSER_UI_VIEWS_PAGE_INFO_WINDOW_H_
-#define CHROME_BROWSER_UI_VIEWS_PAGE_INFO_WINDOW_H_
-#pragma once
-
-#include "content/browser/tab_contents/navigation_entry.h"
-
-class BrowserView;
-class Profile;
-class GURL;
-
-namespace browser {
-
-void ShowPageInfoBubble(BrowserView* browser_view,
- Profile* profile,
- const GURL& url,
- const NavigationEntry::SSLStatus& ssl,
- bool show_history);
-
-} // namespace browser
-
-#endif // CHROME_BROWSER_UI_VIEWS_PAGE_INFO_WINDOW_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index e9aed5e..a2be100 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -3520,7 +3520,6 @@
'browser/ui/views/omnibox/omnibox_view_win.h',
'browser/ui/views/page_info_bubble_view.cc',
'browser/ui/views/page_info_bubble_view.h',
- 'browser/ui/views/page_info_window.h',
'browser/ui/views/reload_button.cc',
'browser/ui/views/reload_button.h',
'browser/ui/views/repost_form_warning_view.cc',
diff --git a/views/bubble/bubble_delegate.cc b/views/bubble/bubble_delegate.cc
index 517878d..b3baea4 100644
--- a/views/bubble/bubble_delegate.cc
+++ b/views/bubble/bubble_delegate.cc
@@ -109,22 +109,20 @@ BubbleDelegateView::~BubbleDelegateView() {
// static
Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) {
bubble_delegate->Init();
- Widget* parent_widget = bubble_delegate->anchor_view() ?
+ Widget* parent = bubble_delegate->anchor_view() ?
bubble_delegate->anchor_view()->GetWidget() : NULL;
- Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent_widget);
+ Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent);
#if defined(OS_WIN) && !defined(USE_AURA)
// 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());
+ bubble_delegate->border_widget_ = CreateBorderWidget(bubble_delegate, parent);
#endif
+ bubble_delegate->SizeToContents();
bubble_widget->AddObserver(bubble_delegate);
- if (parent_widget && parent_widget->GetTopLevelWidget())
- parent_widget->GetTopLevelWidget()->DisableInactiveRendering();
+ if (parent && parent->GetTopLevelWidget())
+ parent->GetTopLevelWidget()->DisableInactiveRendering();
return bubble_widget;
}
@@ -223,10 +221,9 @@ bool BubbleDelegateView::AcceleratorPressed(
return true;
}
-void BubbleDelegateView::Init() {}
-
void BubbleDelegateView::AnimationEnded(const ui::Animation* animation) {
- DCHECK_EQ(animation, fade_animation_.get());
+ if (animation != fade_animation_.get())
+ return;
bool closed = fade_animation_->GetCurrentValue() == 0;
fade_animation_->Reset();
if (closed)
@@ -234,7 +231,8 @@ void BubbleDelegateView::AnimationEnded(const ui::Animation* animation) {
}
void BubbleDelegateView::AnimationProgressed(const ui::Animation* animation) {
- DCHECK_EQ(animation, fade_animation_.get());
+ if (animation != fade_animation_.get())
+ return;
DCHECK(fade_animation_->is_animating());
unsigned char opacity = fade_animation_->GetCurrentValue() * 255;
#if defined(OS_WIN) && !defined(USE_AURA)
@@ -255,6 +253,17 @@ void BubbleDelegateView::AnimationProgressed(const ui::Animation* animation) {
SchedulePaint();
}
+void BubbleDelegateView::Init() {}
+
+void BubbleDelegateView::SizeToContents() {
+#if defined(OS_WIN) && !defined(USE_AURA)
+ border_widget_->SetBounds(GetBubbleBounds());
+ GetWidget()->SetBounds(GetBubbleClientBounds());
+#else
+ GetWidget()->SetBounds(GetBubbleBounds());
+#endif
+}
+
BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const {
const Widget* widget = border_widget_ ? border_widget_ : GetWidget();
return static_cast<BubbleFrameView*>(widget->non_client_view()->frame_view());
@@ -268,11 +277,6 @@ gfx::Rect BubbleDelegateView::GetBubbleBounds() {
}
#if defined(OS_WIN) && !defined(USE_AURA)
-void BubbleDelegateView::InitializeBorderWidget(Widget* parent_widget) {
- border_widget_ = CreateBorderWidget(this, parent_widget);
- border_widget_->SetBounds(GetBubbleBounds());
-}
-
gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const {
gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView());
client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin());
diff --git a/views/bubble/bubble_delegate.h b/views/bubble/bubble_delegate.h
index 55eb2e1..e782b82 100644
--- a/views/bubble/bubble_delegate.h
+++ b/views/bubble/bubble_delegate.h
@@ -90,26 +90,27 @@ class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView,
// View overrides:
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
+ // ui::AnimationDelegate overrides:
+ virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
+ virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
+
// Perform view initialization on the contents for bubble sizing.
virtual void Init();
+ // Resizes and potentially moves the Bubble to best accommodate the
+ // contents preferred size.
+ void SizeToContents();
+
private:
FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewBasicTest, NonClientHitTest);
FRIEND_TEST_ALL_PREFIXES(BubbleDelegateTest, CreateDelegate);
- // ui::AnimationDelegate overrides:
- virtual void AnimationEnded(const ui::Animation* animation);
- virtual void AnimationProgressed(const ui::Animation* animation);
-
BubbleFrameView* GetBubbleFrameView() const;
// Get bubble bounds from the anchor point and client view's preferred size.
gfx::Rect GetBubbleBounds();
#if defined(OS_WIN) && !defined(USE_AURA)
- // Initialize the border widget needed for Windows native control hosting.
- void InitializeBorderWidget(Widget* parent_widget);
-
// Get bounds for the Windows-only widget that hosts the bubble's contents.
gfx::Rect GetBubbleClientBounds() const;
#endif