summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-08 23:13:01 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-08 23:13:01 +0000
commit4d4c0b94960366979943dbe4e3c8880ce80dbdef (patch)
tree1c35f92b0ef05948a2ce13d410961813b5d26127 /chrome/browser
parentb15fcc0b7c29054b67164b248122823dcf0a5a81 (diff)
downloadchromium_src-4d4c0b94960366979943dbe4e3c8880ce80dbdef.zip
chromium_src-4d4c0b94960366979943dbe4e3c8880ce80dbdef.tar.gz
chromium_src-4d4c0b94960366979943dbe4e3c8880ce80dbdef.tar.bz2
Creates a BlockedPopupContainerView interface, and changes the current BlockedPopupContainerView class into a windows specific instance owned by the new BlockedPopupContainer.
http://crbug.com/12843 Review URL: http://codereview.chromium.org/118401 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17905 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/blocked_popup_container.cc61
-rw-r--r--chrome/browser/blocked_popup_container.h93
-rwxr-xr-x[-rw-r--r--]chrome/browser/browser_prefs.cc2
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc10
-rw-r--r--chrome/browser/views/blocked_popup_container_view.h165
-rw-r--r--chrome/browser/views/blocked_popup_container_view_win.cc (renamed from chrome/browser/views/blocked_popup_container_view.cc)295
-rw-r--r--chrome/browser/views/blocked_popup_container_view_win.h96
-rwxr-xr-x[-rw-r--r--]chrome/browser/views/browser_views.vcproj4
8 files changed, 369 insertions, 357 deletions
diff --git a/chrome/browser/blocked_popup_container.cc b/chrome/browser/blocked_popup_container.cc
index ad9c7c6..5c35c66 100644
--- a/chrome/browser/blocked_popup_container.cc
+++ b/chrome/browser/blocked_popup_container.cc
@@ -12,6 +12,23 @@
#include "chrome/common/notification_service.h"
// static
+BlockedPopupContainer* BlockedPopupContainer::Create(
+ TabContents* owner, Profile* profile) {
+ BlockedPopupContainer* container =
+ new BlockedPopupContainer(owner, profile->GetPrefs());
+
+ // TODO(erg): Add different defined(OS_??) as they get subclasses of
+ // BlockedPopupContainerView.
+#if defined(OS_WIN)
+ BlockedPopupContainerView* view =
+ BlockedPopupContainerView::Create(container);
+ container->set_view(view);
+#endif
+
+ return container;
+}
+
+// static
void BlockedPopupContainer::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterListPref(prefs::kPopupWhitelistedHosts);
}
@@ -56,9 +73,8 @@ void BlockedPopupContainer::AddTabContents(TabContents* tab_contents,
else
DCHECK_EQ(whitelisted, i->second);
- // Update UI.
- UpdateLabel();
- ShowSelf();
+ UpdateView();
+ view_->ShowView();
owner_->PopupNotificationVisibilityChanged(true);
}
@@ -109,7 +125,7 @@ void BlockedPopupContainer::ToggleWhitelistingForHost(size_t index) {
whitelist_pref->Append(new StringValue(host));
// Open the popups in order.
- for (size_t j = 0; j < blocked_popups_.size(); ) {
+ for (size_t j = 0; j < blocked_popups_.size();) {
if (blocked_popups_[j].host == host)
LaunchPopupAtIndex(j); // This shifts the rest of the entries down.
else
@@ -151,6 +167,31 @@ void BlockedPopupContainer::CloseAll() {
HideSelf();
}
+void BlockedPopupContainer::Destroy() {
+ view_->Destroy();
+
+ ClearData();
+ GetConstrainingContents(NULL)->WillCloseBlockedPopupContainer(this);
+
+ delete this;
+}
+
+void BlockedPopupContainer::RepositionBlockedPopupContainer() {
+ view_->SetPosition();
+}
+
+TabContents* BlockedPopupContainer::GetTabContentsAt(size_t index) {
+ return blocked_popups_[index].tab_contents;
+}
+
+std::vector<std::string> BlockedPopupContainer::GetHosts() const {
+ std::vector<std::string> hosts;
+ for (PopupHosts::const_iterator i(popup_hosts_.begin());
+ i != popup_hosts_.end(); ++i)
+ hosts.push_back(i->first);
+ return hosts;
+}
+
// Overridden from TabContentsDelegate:
void BlockedPopupContainer::OpenURLFromTab(TabContents* source,
const GURL& url,
@@ -209,6 +250,7 @@ ExtensionFunctionDispatcher* BlockedPopupContainer::
}
void BlockedPopupContainer::HideSelf() {
+ view_->HideView();
owner_->PopupNotificationVisibilityChanged(false);
}
@@ -266,7 +308,7 @@ void BlockedPopupContainer::EraseDataForPopupAndUpdateUI(
// Erase the popup and update the UI.
blocked_popups_.erase(i);
- UpdateLabel();
+ UpdateView();
}
void BlockedPopupContainer::EraseDataForPopupAndUpdateUI(
@@ -301,7 +343,7 @@ void BlockedPopupContainer::EraseDataForPopupAndUpdateUI(
// Erase the popup and update the UI.
unblocked_popups_.erase(i);
- UpdateLabel();
+ UpdateView();
}
@@ -326,6 +368,13 @@ BlockedPopupContainer::BlockedPopupContainer(TabContents* owner,
}
}
+void BlockedPopupContainer::UpdateView() {
+ if (blocked_popups_.empty() && unblocked_popups_.empty())
+ HideSelf();
+ else
+ view_->UpdateLabel();
+}
+
void BlockedPopupContainer::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
diff --git a/chrome/browser/blocked_popup_container.h b/chrome/browser/blocked_popup_container.h
index f9b5d14..66d298b 100644
--- a/chrome/browser/blocked_popup_container.h
+++ b/chrome/browser/blocked_popup_container.h
@@ -12,6 +12,8 @@
#include <map>
#include <set>
+#include <string>
+#include <vector>
#include "base/gfx/native_widget_types.h"
#include "base/gfx/rect.h"
@@ -19,40 +21,43 @@
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/common/notification_registrar.h"
-class BlockedPopupContainerImpl;
+class BlockedPopupContainer;
class PrefService;
class Profile;
class TabContents;
+// Interface that the BlockedPopupContainer model/controller uses to
+// communicate with its platform specific view.
+class BlockedPopupContainerView {
+ public:
+ // Platform specific constructor used by BlockedPopupContainer to create a
+ // view that is displayed to the user.
+ static BlockedPopupContainerView* Create(BlockedPopupContainer* container);
+
+ // Notification that the view should properly position itself in |view|.
+ virtual void SetPosition() = 0;
+
+ // Shows the blocked popup view / Animates the blocked popup view in.
+ virtual void ShowView() = 0;
+
+ // Sets the text in the blocked popup label.
+ virtual void UpdateLabel() = 0;
+
+ // Hides the blocked popup view / Animates the blocked popup view out.
+ virtual void HideView() = 0;
+
+ // Called by the BlockedPopupContainer that owns us. Destroys the view or
+ // starts a delayed Task to destroy the View at some later time.
+ virtual void Destroy() = 0;
+};
+
// Takes ownership of TabContents that are unrequested popup windows and
// presents an interface to the user for launching them. (Or never showing them
// again). This class contains all the cross-platform bits that can be used in
// all ports.
//
-// Currently, BlockedPopupContainer only exists as a cross platform model
-// extracted from browser/views/blocked_popup_container.cc. This is what it
-// used to look like before:
-//
-// +- BlockedPopupContainer -------------------------------+
-// | <views::WidgetWin> |
-// | All model logic. |
-// | All views code. |
-// +-------------------------------------------------------+
-//
-// As of now, it looks like this:
-//
-// +- BlockedPopupContainer -------------------------------+
-// | All model logic |
-// +-------------------------------------------------------+
-// ^
-// |
-// +- BlockedPopupContainerImpl ---------------------------+
-// | views::WidgetWin |
-// | All views code. |
-// | |
-// +-------------------------------------------------------+
-//
-// TODO(erg): While it is not in this state yet, I want it to look like this:
+// TODO(erg): The GTK and Cocoa versions of the view class haven't been written
+// yet.
//
// +- BlockedPopupContainer ---+ +- BlockedPopupContainerView -----+
// | All model logic | +--->| Abstract cross platform |
@@ -75,11 +80,14 @@ class BlockedPopupContainer : public TabContentsDelegate,
public:
// Creates a BlockedPopupContainer, anchoring the container to the lower
// right corner.
- static BlockedPopupContainer* Create(
- TabContents* owner, Profile* profile, const gfx::Point& initial_anchor);
+ static BlockedPopupContainer* Create(TabContents* owner, Profile* profile);
static void RegisterUserPrefs(PrefService* prefs);
+ // Sets this BlockedPopupContainer's view. BlockedPopupContainer now owns
+ // |view| and is responsible for calling Destroy() on it.
+ void set_view(BlockedPopupContainerView* view) { view_ = view; }
+
// Adds a popup to this container. |bounds| are the window bounds requested by
// the popup window.
void AddTabContents(TabContents* tab_contents,
@@ -104,11 +112,20 @@ class BlockedPopupContainer : public TabContentsDelegate,
void CloseAll();
// Sets this object up to delete itself.
- virtual void Destroy() = 0;
+ void Destroy();
// Message called when a BlockedPopupContainer should move itself to the
- // bottom right corner of |view|.
- virtual void RepositionBlockedPopupContainer(gfx::NativeView view) = 0;
+ // bottom right corner of our parent view.
+ void RepositionBlockedPopupContainer();
+
+ // Returns the TabContents for the blocked popup |index|.
+ TabContents* GetTabContentsAt(size_t index);
+
+ // Returns the names of hosts showing popups.
+ std::vector<std::string> GetHosts() const;
+
+ // Deletes all local state.
+ void ClearData();
// Called to force this container to never show itself again.
void set_dismissed() { has_been_dismissed_ = true; }
@@ -189,18 +206,9 @@ class BlockedPopupContainer : public TabContentsDelegate,
// string is hostname. bool is whitelisted status.
typedef std::map<std::string, bool> PopupHosts;
- // Shows the UI.
- virtual void ShowSelf() = 0;
-
// Hides the UI portion of the container.
virtual void HideSelf();
- // Updates the text on the label on the notification.
- virtual void UpdateLabel() = 0;
-
- // Deletes all local state.
- virtual void ClearData();
-
// Helper function to convert a host index (which the view uses) into an
// iterator into |popup_hosts_|. Returns popup_hosts_.end() if |index| is
// invalid.
@@ -223,6 +231,10 @@ class BlockedPopupContainer : public TabContentsDelegate,
// Creates a container for a certain TabContents:
BlockedPopupContainer(TabContents* owner, PrefService* prefs);
+ // Either hides the view if there are no popups, or updates the label if
+ // there are.
+ void UpdateView();
+
// Overridden from notificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
@@ -252,6 +264,9 @@ class BlockedPopupContainer : public TabContentsDelegate,
// Information about all popup hosts.
PopupHosts popup_hosts_;
+ // Our platform specific view.
+ BlockedPopupContainerView* view_;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedPopupContainer);
};
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc
index d208a3f..ffb1025f 100644..100755
--- a/chrome/browser/browser_prefs.cc
+++ b/chrome/browser/browser_prefs.cc
@@ -25,7 +25,7 @@
#if defined(OS_WIN) // TODO(port): whittle this down as we port
#include "chrome/browser/task_manager.h"
-#include "chrome/browser/views/blocked_popup_container_view.h"
+#include "chrome/browser/views/blocked_popup_container_view_win.h"
#include "chrome/browser/views/frame/browser_view.h"
#include "chrome/browser/views/keyword_editor_view.h"
#include "chrome/browser/views/page_info_window.h"
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index ddf2b9d..db21d93 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -1076,13 +1076,7 @@ void TabContents::CreateBlockedPopupContainerIfNecessary() {
if (blocked_popups_)
return;
- CRect client_rect;
- GetClientRect(GetNativeView(), &client_rect);
- gfx::Point anchor_position(
- client_rect.Width() - views::NativeScrollBar::GetVerticalScrollBarWidth(),
- client_rect.Height());
- blocked_popups_ = BlockedPopupContainer::Create(this, profile(),
- anchor_position);
+ blocked_popups_ = BlockedPopupContainer::Create(this, profile());
}
void TabContents::AddPopup(TabContents* new_contents,
@@ -1096,7 +1090,7 @@ void TabContents::AddPopup(TabContents* new_contents,
// TODO(brettw) This should be on the TabContentsView.
void TabContents::RepositionSupressedPopupsToFit() {
if (blocked_popups_)
- blocked_popups_->RepositionBlockedPopupContainer(GetNativeView());
+ blocked_popups_->RepositionBlockedPopupContainer();
}
bool TabContents::ShowingBlockedPopupNotification() const {
diff --git a/chrome/browser/views/blocked_popup_container_view.h b/chrome/browser/views/blocked_popup_container_view.h
deleted file mode 100644
index 50042d5..0000000
--- a/chrome/browser/views/blocked_popup_container_view.h
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright (c) 2008 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_VIEWS_BLOCKED_POPUP_CONTAINER_VIEW_H_
-#define CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_VIEW_H_
-
-#include <set>
-#include <utility>
-#include <vector>
-
-#include "app/animation.h"
-#include "base/gfx/native_widget_types.h"
-#include "base/gfx/rect.h"
-#include "chrome/browser/blocked_popup_container.h"
-#include "chrome/browser/tab_contents/tab_contents_delegate.h"
-#include "views/controls/button/button.h"
-#include "views/controls/button/menu_button.h"
-#include "views/controls/menu/menu.h"
-#include "views/view.h"
-#include "views/widget/widget_win.h"
-
-class BlockedPopupContainerImpl;
-class PrefService;
-class Profile;
-class TabContents;
-class TextButton;
-
-namespace views {
-class ImageButton;
-}
-
-// The view presented to the user notifying them of the number of popups
-// blocked. This view should only be used inside of BlockedPopupContainer.
-class BlockedPopupContainerView : public views::View,
- public views::ButtonListener,
- public views::Menu::Delegate {
- public:
- explicit BlockedPopupContainerView(BlockedPopupContainerImpl* container);
- ~BlockedPopupContainerView();
-
- // Sets the label on the menu button
- void UpdateLabel();
-
- std::wstring label() const { return popup_count_label_->text(); }
-
- // Overridden from views::View:
-
- // Paints our border and background. (Does not paint children.)
- virtual void Paint(gfx::Canvas* canvas);
- // Sets positions of all child views.
- virtual void Layout();
- // Gets the desired size of the popup notification.
- virtual gfx::Size GetPreferredSize();
-
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender);
-
- // Overridden from Menu::Delegate:
-
- // Displays the status of the "Show Blocked Popup Notification" item.
- virtual bool IsItemChecked(int id) const;
- // Called after user clicks a menu item.
- virtual void ExecuteCommand(int id);
-
- private:
- // Our owner and HWND parent.
- BlockedPopupContainerImpl* container_;
-
- // The button which brings up the popup menu.
- views::MenuButton* popup_count_label_;
-
- // Our "X" button.
- views::ImageButton* close_button_;
-
- // Popup menu shown to user.
- scoped_ptr<views::Menu> launch_menu_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedPopupContainerView);
-};
-
-// Takes ownership of TabContents that are unrequested popup windows and
-// presents an interface to the user for launching them. (Or never showing them
-// again).
-//
-// TODO(erg): When this class goes away, whatever is replaced shouldn't
-// multiply inherit.
-class BlockedPopupContainerImpl : public BlockedPopupContainer,
- public Animation,
- public views::WidgetWin {
- public:
- virtual ~BlockedPopupContainerImpl();
-
- // Returns the URL and title for popup |index|, used to construct a string for
- // display.
- void GetURLAndTitleForPopup(size_t index,
- std::wstring* url,
- std::wstring* title) const;
-
- // Returns the names of hosts showing popups.
- std::vector<std::wstring> GetHosts() const;
-
- virtual void Destroy();
-
- virtual void RepositionBlockedPopupContainer(gfx::NativeView view);
-
- private:
- friend class BlockedPopupContainer;
-
- // Creates a container for a certain TabContents.
- BlockedPopupContainerImpl(TabContents* owner, PrefService* prefs);
-
- // Repositions our blocked popup notification so that the lower right corner
- // is at |anchor_point|.
- void RepositionWindowTo(const gfx::Point& anchor_point);
-
- // Overridden from Animation:
- // Changes the visibility percentage of the BlockedPopupContainerImpl. This is
- // called while animating in or out.
- virtual void AnimateToState(double state);
-
- // Overridden from views::WidgetWin:
-
- // Alerts our |owner_| that we are closing ourselves. Cleans up any remaining
- // blocked popups.
- virtual void OnFinalMessage(HWND window);
-
- // Makes the top corners of the window rounded during resizing events.
- virtual void OnSize(UINT param, const CSize& size);
-
- // Initializes our Views and positions us to the lower right corner of the
- // browser window.
- void Init(const gfx::Point& initial_anchor);
-
- // Shows the UI.
- virtual void ShowSelf();
-
- // Hides the UI portion of the container.
- virtual void HideSelf();
-
- virtual void UpdateLabel();
-
- // Sets our position, based on our |anchor_point_| and on our
- // |visibility_percentage_|. This method is called whenever either of those
- // change.
- void SetPosition();
-
- // Our associated view object.
- BlockedPopupContainerView* container_view_;
-
- // True while animating in; false while animating out.
- bool in_show_animation_;
-
- // Percentage of the window to show; used to animate in the notification.
- double visibility_percentage_;
-
- // The bounds to report to the automation system (may not equal our actual
- // bounds while animating in or out).
- gfx::Rect bounds_;
-
- // The bottom right corner of where we should appear in our parent window.
- gfx::Point anchor_point_;
-};
-
-#endif
diff --git a/chrome/browser/views/blocked_popup_container_view.cc b/chrome/browser/views/blocked_popup_container_view_win.cc
index edb7c7e..89a0694 100644
--- a/chrome/browser/views/blocked_popup_container_view.cc
+++ b/chrome/browser/views/blocked_popup_container_view_win.cc
@@ -1,14 +1,8 @@
-// Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this
+// Copyright (c) 2009 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.
-// Implementation of BlockedPopupContainer and its corresponding View
-// class. The BlockedPopupContainer is the sort of Model class which owns the
-// blocked popups' TabContents (but like most Chromium interface code, it there
-// isn't a strict Model/View separation), and BlockedPopupContainerView
-// presents the user interface controls, creates and manages the popup menu.
-
-#include "chrome/browser/views/blocked_popup_container_view.h"
+#include "chrome/browser/views/blocked_popup_container_view_win.h"
#include <math.h>
#include <windows.h>
@@ -40,13 +34,6 @@ const SkColor kBackgroundColorBottom = SkColorSetRGB(250, 230, 145);
// The border color of the blocked popup notification. This is the same as the
// border around the inside of the tab contents.
const SkColor kBorderColor = SkColorSetRGB(190, 205, 223);
-// Thickness of the border.
-const int kBorderSize = 1;
-
-// Duration of the showing/hiding animations.
-const int kShowAnimationDurationMS = 200;
-const int kHideAnimationDurationMS = 120;
-const int kFramerate = 25;
// So that the MenuButton doesn't change its size as its text changes, during
// construction we feed it the strings it will be displaying, so it can set the
@@ -76,8 +63,60 @@ const SkScalar kRoundedCornerRad[8] = {
} // namespace
-BlockedPopupContainerView::BlockedPopupContainerView(
- BlockedPopupContainerImpl* container)
+
+// The view presented to the user notifying them of the number of popups
+// blocked. This view should only be used inside of BlockedPopupContainer.
+class BlockedPopupContainerInternalView : public views::View,
+ public views::ButtonListener,
+ public views::Menu::Delegate {
+ public:
+ explicit BlockedPopupContainerInternalView(
+ BlockedPopupContainerViewWin* container);
+ ~BlockedPopupContainerInternalView();
+
+ // Sets the label on the menu button.
+ void UpdateLabel();
+
+ std::wstring label() const { return popup_count_label_->text(); }
+
+ // Overridden from views::View:
+
+ // Paints our border and background. (Does not paint children.)
+ virtual void Paint(gfx::Canvas* canvas);
+ // Sets positions of all child views.
+ virtual void Layout();
+ // Gets the desired size of the popup notification.
+ virtual gfx::Size GetPreferredSize();
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender);
+
+ // Overridden from Menu::Delegate:
+
+ // Displays the status of the "Show Blocked Popup Notification" item.
+ virtual bool IsItemChecked(int id) const;
+ // Called after user clicks a menu item.
+ virtual void ExecuteCommand(int id);
+
+ private:
+ // Our owner and HWND parent.
+ BlockedPopupContainerViewWin* container_;
+
+ // The button which brings up the popup menu.
+ views::MenuButton* popup_count_label_;
+
+ // Our "X" button.
+ views::ImageButton* close_button_;
+
+ // Popup menu shown to user.
+ scoped_ptr<views::Menu> launch_menu_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(BlockedPopupContainerInternalView);
+};
+
+
+BlockedPopupContainerInternalView::BlockedPopupContainerInternalView(
+ BlockedPopupContainerViewWin* container)
: container_(container) {
ResourceBundle &resource_bundle = ResourceBundle::GetSharedInstance();
@@ -108,10 +147,10 @@ BlockedPopupContainerView::BlockedPopupContainerView(
UpdateLabel();
}
-BlockedPopupContainerView::~BlockedPopupContainerView() {
+BlockedPopupContainerInternalView::~BlockedPopupContainerInternalView() {
}
-void BlockedPopupContainerView::UpdateLabel() {
+void BlockedPopupContainerInternalView::UpdateLabel() {
size_t blocked_popups = container_->GetBlockedPopupCount();
popup_count_label_->SetText((blocked_popups > 0) ?
l10n_util::GetStringF(IDS_POPUPS_BLOCKED_COUNT,
@@ -121,7 +160,7 @@ void BlockedPopupContainerView::UpdateLabel() {
SchedulePaint();
}
-void BlockedPopupContainerView::Paint(gfx::Canvas* canvas) {
+void BlockedPopupContainerInternalView::Paint(gfx::Canvas* canvas) {
// Draw the standard background.
View::Paint(canvas);
@@ -138,7 +177,7 @@ void BlockedPopupContainerView::Paint(gfx::Canvas* canvas) {
canvas->drawPath(border_path, border_paint);
}
-void BlockedPopupContainerView::Layout() {
+void BlockedPopupContainerInternalView::Layout() {
gfx::Size panel_size = GetPreferredSize();
gfx::Size button_size = close_button_->GetPreferredSize();
gfx::Size size = popup_count_label_->GetPreferredSize();
@@ -156,7 +195,7 @@ void BlockedPopupContainerView::Layout() {
button_size.height());
}
-gfx::Size BlockedPopupContainerView::GetPreferredSize() {
+gfx::Size BlockedPopupContainerInternalView::GetPreferredSize() {
gfx::Size preferred_size = popup_count_label_->GetPreferredSize();
preferred_size.Enlarge(close_button_->GetPreferredSize().width(), 0);
// Add padding to all sides of the |popup_count_label_| except the right.
@@ -173,7 +212,7 @@ gfx::Size BlockedPopupContainerView::GetPreferredSize() {
return preferred_size;
}
-void BlockedPopupContainerView::ButtonPressed(views::Button* sender) {
+void BlockedPopupContainerInternalView::ButtonPressed(views::Button* sender) {
if (sender == popup_count_label_) {
launch_menu_.reset(views::Menu::Create(this, views::Menu::TOPLEFT,
container_->GetNativeView()));
@@ -206,173 +245,112 @@ void BlockedPopupContainerView::ButtonPressed(views::Button* sender) {
::GetCursorPos(&cursor_position);
launch_menu_->RunMenuAt(cursor_position.x, cursor_position.y);
} else if (sender == close_button_) {
- container_->set_dismissed();
- container_->CloseAll();
+ container_->GetModel()->set_dismissed();
+ container_->GetModel()->CloseAll();
}
}
-bool BlockedPopupContainerView::IsItemChecked(int id) const {
+bool BlockedPopupContainerInternalView::IsItemChecked(int id) const {
if (id > BlockedPopupContainer::kImpossibleNumberOfPopups) {
- return container_->IsHostWhitelisted(static_cast<size_t>(
+ return container_->GetModel()->IsHostWhitelisted(static_cast<size_t>(
id - BlockedPopupContainer::kImpossibleNumberOfPopups - 1));
}
return false;
}
-void BlockedPopupContainerView::ExecuteCommand(int id) {
+void BlockedPopupContainerInternalView::ExecuteCommand(int id) {
DCHECK_GT(id, 0);
size_t id_size_t = static_cast<size_t>(id);
if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups) {
// Decrement id since all index based commands have 1 added to them. (See
// ButtonPressed() for detail).
- container_->ToggleWhitelistingForHost(
+ container_->GetModel()->ToggleWhitelistingForHost(
id_size_t - BlockedPopupContainer::kImpossibleNumberOfPopups - 1);
} else {
- container_->LaunchPopupAtIndex(id_size_t - 1);
+ container_->GetModel()->LaunchPopupAtIndex(id_size_t - 1);
}
}
-BlockedPopupContainerImpl::~BlockedPopupContainerImpl() {
-}
// static
-BlockedPopupContainer* BlockedPopupContainer::Create(
- TabContents* owner, Profile* profile, const gfx::Point& initial_anchor) {
- BlockedPopupContainerImpl* container =
- new BlockedPopupContainerImpl(owner, profile->GetPrefs());
- container->Init(initial_anchor);
- return container;
+BlockedPopupContainerView* BlockedPopupContainerView::Create(
+ BlockedPopupContainer* container) {
+ return new BlockedPopupContainerViewWin(container);
}
-void BlockedPopupContainerImpl::GetURLAndTitleForPopup(size_t index,
- std::wstring* url,
- std::wstring* title) const {
+
+BlockedPopupContainerViewWin::~BlockedPopupContainerViewWin() {
+}
+
+void BlockedPopupContainerViewWin::GetURLAndTitleForPopup(
+ size_t index, std::wstring* url, std::wstring* title) const {
DCHECK(url);
DCHECK(title);
- TabContents* tab_contents = blocked_popups_[index].tab_contents;
+ TabContents* tab_contents = GetModel()->GetTabContentsAt(index);
const GURL& tab_contents_url = tab_contents->GetURL().GetOrigin();
*url = UTF8ToWide(tab_contents_url.possibly_invalid_spec());
*title = UTF16ToWideHack(tab_contents->GetTitle());
}
-std::vector<std::wstring> BlockedPopupContainerImpl::GetHosts() const {
+std::vector<std::wstring> BlockedPopupContainerViewWin::GetHosts() const {
+ std::vector<std::string> utf8_hosts(GetModel()->GetHosts());
+
std::vector<std::wstring> hosts;
- for (PopupHosts::const_iterator i(popup_hosts_.begin());
- i != popup_hosts_.end(); ++i)
- hosts.push_back(UTF8ToWide(i->first));
+ for (std::vector<std::string>::const_iterator it = utf8_hosts.begin();
+ it != utf8_hosts.end(); ++it)
+ hosts.push_back(UTF8ToWide(*it));
return hosts;
}
-// Overridden from ConstrainedWindow:
-void BlockedPopupContainerImpl::Destroy() {
- ClearData();
- Close();
-}
-
-void BlockedPopupContainerImpl::RepositionBlockedPopupContainer(
- gfx::NativeView view) {
- if (::IsWindow(view)) {
- CRect client_rect;
- ::GetClientRect(view, &client_rect);
-
- // TODO(erg): There's no way to detect whether scroll bars are
- // visible, so for beta, we're just going to assume that the
- // vertical scroll bar is visible, and not care about covering up
- // the horizontal scroll bar. Fixing this is half of
- // http://b/1118139.
- gfx::Point anchor_position(
- client_rect.Width() -
- views::NativeScrollBar::GetVerticalScrollBarWidth(),
- client_rect.Height());
-
- RepositionWindowTo(anchor_position);
- }
+size_t BlockedPopupContainerViewWin::GetBlockedPopupCount() const {
+ return container_model_->GetBlockedPopupCount();
}
-// private:
+// Overridden from AnimationDelegate:
-BlockedPopupContainerImpl::BlockedPopupContainerImpl(TabContents* owner,
- PrefService* prefs)
- : BlockedPopupContainer(owner, prefs),
- Animation(kFramerate, NULL),
- container_view_(NULL),
- in_show_animation_(false),
- visibility_percentage_(0) {
-}
-
-void BlockedPopupContainerImpl::RepositionWindowTo(
- const gfx::Point& anchor_point) {
- anchor_point_ = anchor_point;
+void BlockedPopupContainerViewWin::AnimationStarted(
+ const Animation* animation) {
SetPosition();
}
-void BlockedPopupContainerImpl::AnimateToState(double state) {
- visibility_percentage_ = in_show_animation_ ? state : (1 - state);
+void BlockedPopupContainerViewWin::AnimationEnded(const Animation* animation) {
SetPosition();
}
-void BlockedPopupContainerImpl::OnFinalMessage(HWND window) {
- GetConstrainingContents(NULL)->WillCloseBlockedPopupContainer(this);
- ClearData();
- WidgetWin::OnFinalMessage(window);
-}
-
-void BlockedPopupContainerImpl::OnSize(UINT param, const CSize& size) {
- // Set the window region so we have rounded corners on the top.
- SkRect rect;
- rect.set(0, 0, SkIntToScalar(size.cx), SkIntToScalar(size.cy));
- gfx::Path path;
- path.addRoundRect(rect, kRoundedCornerRad, SkPath::kCW_Direction);
- SetWindowRgn(path.CreateHRGN(), TRUE);
-
- ChangeSize(param, size);
-}
-
-void BlockedPopupContainerImpl::Init(const gfx::Point& initial_anchor) {
- container_view_ = new BlockedPopupContainerView(this);
- container_view_->SetVisible(true);
-
- set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
- WidgetWin::Init(GetConstrainingContents(NULL)->GetNativeView(), gfx::Rect(),
- false);
- SetContentsView(container_view_);
- RepositionWindowTo(initial_anchor);
+void BlockedPopupContainerViewWin::AnimationProgressed(
+ const Animation* animation) {
+ SetPosition();
}
-void BlockedPopupContainerImpl::ShowSelf() {
- SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
- if (!Animation::IsAnimating() && visibility_percentage_ < 1.0) {
- in_show_animation_ = true;
- Animation::SetDuration(kShowAnimationDurationMS);
- Animation::Start();
- }
-}
+// Overridden from BlockedPopupContainerView:
-void BlockedPopupContainerImpl::HideSelf() {
- in_show_animation_ = false;
- Animation::SetDuration(kHideAnimationDurationMS);
- Animation::Start();
- BlockedPopupContainer::HideSelf();
-}
+void BlockedPopupContainerViewWin::SetPosition() {
+ // Get our parent's rect and size ourselves inside of it.
+ HWND parent = GetParent();
+ CRect client_rect;
+ ::GetClientRect(parent, &client_rect);
-void BlockedPopupContainerImpl::UpdateLabel() {
- if (blocked_popups_.empty() && unblocked_popups_.empty())
- HideSelf();
- else
- container_view_->UpdateLabel();
-}
+ // TODO(erg): There's no way to detect whether scroll bars are
+ // visible, so for beta, we're just going to assume that the
+ // vertical scroll bar is visible, and not care about covering up
+ // the horizontal scroll bar. Fixing this is half of
+ // http://b/1118139.
+ gfx::Point anchor_point(
+ client_rect.Width() -
+ views::NativeScrollBar::GetVerticalScrollBarWidth(),
+ client_rect.Height());
-void BlockedPopupContainerImpl::SetPosition() {
gfx::Size size = container_view_->GetPreferredSize();
- int base_x = anchor_point_.x() - size.width();
- int base_y = anchor_point_.y() - size.height();
+ int base_x = anchor_point.x() - size.width();
+ int base_y = anchor_point.y() - size.height();
// The bounds we report through the automation system are the real bounds;
// the animation is short lived...
bounds_ = gfx::Rect(gfx::Point(base_x, base_y), size);
- int real_height = static_cast<int>(size.height() * visibility_percentage_);
- int real_y = anchor_point_.y() - real_height;
+ int real_height =
+ static_cast<int>(size.height() * slide_animation_->GetCurrentValue());
+ int real_y = anchor_point.y() - real_height;
if (real_height > 0) {
int x;
@@ -393,3 +371,48 @@ void BlockedPopupContainerImpl::SetPosition() {
SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
}
}
+
+void BlockedPopupContainerViewWin::ShowView() {
+ SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
+ slide_animation_->Show();
+}
+
+void BlockedPopupContainerViewWin::UpdateLabel() {
+ container_view_->UpdateLabel();
+}
+
+void BlockedPopupContainerViewWin::HideView() {
+ slide_animation_->Hide();
+}
+
+void BlockedPopupContainerViewWin::Destroy() {
+ Close();
+}
+
+// private:
+
+BlockedPopupContainerViewWin::BlockedPopupContainerViewWin(
+ BlockedPopupContainer* container)
+ : slide_animation_(new SlideAnimation(this)),
+ container_model_(container),
+ container_view_(NULL) {
+ container_view_ = new BlockedPopupContainerInternalView(this);
+ container_view_->SetVisible(true);
+
+ set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
+ WidgetWin::Init(GetModel()->GetConstrainingContents(NULL)->GetNativeView(),
+ gfx::Rect(), false);
+ SetContentsView(container_view_);
+ SetPosition();
+}
+
+void BlockedPopupContainerViewWin::OnSize(UINT param, const CSize& size) {
+ // Set the window region so we have rounded corners on the top.
+ SkRect rect;
+ rect.set(0, 0, SkIntToScalar(size.cx), SkIntToScalar(size.cy));
+ gfx::Path path;
+ path.addRoundRect(rect, kRoundedCornerRad, SkPath::kCW_Direction);
+ SetWindowRgn(path.CreateHRGN(), TRUE);
+
+ ChangeSize(param, size);
+}
diff --git a/chrome/browser/views/blocked_popup_container_view_win.h b/chrome/browser/views/blocked_popup_container_view_win.h
new file mode 100644
index 0000000..57f4685
--- /dev/null
+++ b/chrome/browser/views/blocked_popup_container_view_win.h
@@ -0,0 +1,96 @@
+// Copyright (c) 2009 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_VIEWS_BLOCKED_POPUP_CONTAINER_VIEW_WIN_H_
+#define CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_VIEW_WIN_H_
+
+#include <set>
+#include <utility>
+#include <vector>
+
+#include "app/slide_animation.h"
+#include "base/gfx/native_widget_types.h"
+#include "base/gfx/rect.h"
+#include "chrome/browser/blocked_popup_container.h"
+#include "chrome/browser/tab_contents/tab_contents_delegate.h"
+#include "views/controls/button/button.h"
+#include "views/controls/button/menu_button.h"
+#include "views/controls/menu/menu.h"
+#include "views/view.h"
+#include "views/widget/widget_win.h"
+
+class BlockedPopupContainerInternalView;
+class PrefService;
+class Profile;
+class TabContents;
+class TextButton;
+
+namespace views {
+class ImageButton;
+}
+
+// Takes ownership of TabContents that are unrequested popup windows and
+// presents an interface to the user for launching them. (Or never showing them
+// again).
+class BlockedPopupContainerViewWin : public BlockedPopupContainerView,
+ public AnimationDelegate,
+ public views::WidgetWin {
+ public:
+ virtual ~BlockedPopupContainerViewWin();
+
+ // Returns the URL and title for popup |index|, used to construct a string for
+ // display.
+ void GetURLAndTitleForPopup(size_t index,
+ std::wstring* url,
+ std::wstring* title) const;
+
+ // Returns the names of hosts showing popups.
+ std::vector<std::wstring> GetHosts() const;
+
+ // Returns the number of blocked popups from the model
+ size_t GetBlockedPopupCount() const;
+
+ // Returns the model that owns us.
+ BlockedPopupContainer* GetModel() const { return container_model_; }
+
+ // Overridden from AnimationDelegate:
+ virtual void AnimationStarted(const Animation* animation);
+ virtual void AnimationEnded(const Animation* animation);
+ virtual void AnimationProgressed(const Animation* animation);
+
+ // Overridden from BlockedPopupContainerView:
+ virtual void SetPosition();
+ virtual void ShowView();
+ virtual void UpdateLabel();
+ virtual void HideView();
+ virtual void Destroy();
+
+ private:
+ friend class BlockedPopupContainerView;
+
+ // Creates a container for a certain TabContents.
+ explicit BlockedPopupContainerViewWin(BlockedPopupContainer* container);
+
+ // Overridden from views::WidgetWin:
+
+ // Makes the top corners of the window rounded during resizing events.
+ virtual void OnSize(UINT param, const CSize& size);
+
+ // Our model; calling the shots.
+ BlockedPopupContainer* container_model_;
+
+ // Our associated view object.
+ BlockedPopupContainerInternalView* container_view_;
+
+ // The animation that slides us up and down.
+ scoped_ptr<SlideAnimation> slide_animation_;
+
+ // The bounds to report to the automation system (may not equal our actual
+ // bounds while animating in or out).
+ gfx::Rect bounds_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlockedPopupContainerViewWin);
+};
+
+#endif // CHROME_BROWSER_VIEWS_BLOCKED_POPUP_CONTAINER_VIEW_WIN_H_
diff --git a/chrome/browser/views/browser_views.vcproj b/chrome/browser/views/browser_views.vcproj
index b2ddb8b..435f65b 100644..100755
--- a/chrome/browser/views/browser_views.vcproj
+++ b/chrome/browser/views/browser_views.vcproj
@@ -460,11 +460,11 @@
>
</File>
<File
- RelativePath=".\blocked_popup_container_view.cc"
+ RelativePath=".\blocked_popup_container_view_win.cc"
>
</File>
<File
- RelativePath=".\blocked_popup_container_view.h"
+ RelativePath=".\blocked_popup_container_view_win.h"
>
</File>
<File