diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-30 00:21:52 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-30 00:21:52 +0000 |
commit | aa22af6dc85d5c002ff4f8a870e79c3a9c903008 (patch) | |
tree | 1f204d0026b5e57f2f94bd154b67c754614f20c8 | |
parent | c178cb1749d4488628caf1e1bac6d17878d20fc2 (diff) | |
download | chromium_src-aa22af6dc85d5c002ff4f8a870e79c3a9c903008.zip chromium_src-aa22af6dc85d5c002ff4f8a870e79c3a9c903008.tar.gz chromium_src-aa22af6dc85d5c002ff4f8a870e79c3a9c903008.tar.bz2 |
browser: Fix confirm_bubble_* platform-specific filenames.
And while I'm here rename the classes to match with the filenames and also extract the Show function from ConfirmBubbleModel into browser namespace.
R=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10446045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139438 0039d316-1c4b-4281-b951-d872f2087c98
16 files changed, 181 insertions, 144 deletions
diff --git a/chrome/browser/tab_contents/spelling_bubble_model.h b/chrome/browser/tab_contents/spelling_bubble_model.h index 82f1a35..57440da 100644 --- a/chrome/browser/tab_contents/spelling_bubble_model.h +++ b/chrome/browser/tab_contents/spelling_bubble_model.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -6,8 +6,8 @@ #define CHROME_BROWSER_TAB_CONTENTS_SPELLING_BUBBLE_MODEL_H_ #pragma once +#include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/string16.h" #include "chrome/browser/ui/confirm_bubble_model.h" class Profile; @@ -31,6 +31,8 @@ class SpellingBubbleModel : public ConfirmBubbleModel { private: Profile* profile_; + + DISALLOW_COPY_AND_ASSIGN(SpellingBubbleModel); }; #endif // CHROME_BROWSER_TAB_CONTENTS_SPELLING_BUBBLE_MODEL_H_ diff --git a/chrome/browser/tab_contents/spelling_menu_observer.cc b/chrome/browser/tab_contents/spelling_menu_observer.cc index c9255b7..29fe6e6 100644 --- a/chrome/browser/tab_contents/spelling_menu_observer.cc +++ b/chrome/browser/tab_contents/spelling_menu_observer.cc @@ -17,6 +17,7 @@ #include "chrome/browser/spellchecker/spelling_service_client.h" #include "chrome/browser/tab_contents/render_view_context_menu.h" #include "chrome/browser/tab_contents/spelling_bubble_model.h" +#include "chrome/browser/ui/confirm_bubble.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/common/spellcheck_result.h" @@ -232,9 +233,9 @@ void SpellingMenuObserver::ExecuteCommand(int command_id) { if (!integrate_spelling_service_) { content::RenderViewHost* rvh = proxy_->GetRenderViewHost(); gfx::Rect rect = rvh->GetView()->GetViewBounds(); - ConfirmBubbleModel::Show(rvh->GetView()->GetNativeView(), - gfx::Point(rect.CenterPoint().x(), rect.y()), - new SpellingBubbleModel(proxy_->GetProfile())); + browser::ShowConfirmBubble(rvh->GetView()->GetNativeView(), + gfx::Point(rect.CenterPoint().x(), rect.y()), + new SpellingBubbleModel(proxy_->GetProfile())); } else { Profile* profile = proxy_->GetProfile(); if (profile) diff --git a/chrome/browser/ui/cocoa/confirm_bubble_view.h b/chrome/browser/ui/cocoa/confirm_bubble_cocoa.h index bb46299..cc54490 100644 --- a/chrome/browser/ui/cocoa/confirm_bubble_view.h +++ b/chrome/browser/ui/cocoa/confirm_bubble_cocoa.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_VIEW_H_ -#define CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_VIEW_H_ +#ifndef CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_COCOA_H_ +#define CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_COCOA_H_ #pragma once #import <Cocoa/Cocoa.h> @@ -33,7 +33,7 @@ class ConfirmBubbleModel; // | [Cancel] [OK] | // +------------------------+ // -@interface ConfirmBubbleView : NSView<NSTextViewDelegate> { +@interface ConfirmBubbleCocoa : NSView<NSTextViewDelegate> { @private NSView* parent_; // weak ConfirmBubbleController* controller_; // weak @@ -55,10 +55,10 @@ class ConfirmBubbleModel; @end // Exposed only for unit testing. -@interface ConfirmBubbleView (ExposedForUnitTesting) +@interface ConfirmBubbleCocoa (ExposedForUnitTesting) - (void)clickOk; - (void)clickCancel; - (void)clickLink; @end -#endif // CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_VIEW_H_ +#endif // CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_COCOA_H_ diff --git a/chrome/browser/ui/cocoa/confirm_bubble_view.mm b/chrome/browser/ui/cocoa/confirm_bubble_cocoa.mm index f81b410..68d860b 100644 --- a/chrome/browser/ui/cocoa/confirm_bubble_view.mm +++ b/chrome/browser/ui/cocoa/confirm_bubble_cocoa.mm @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "chrome/browser/ui/cocoa/confirm_bubble_view.h" +#import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h" -#include "base/string16.h" #import "base/mac/cocoa_protocols.h" +#include "base/string16.h" #include "chrome/browser/themes/theme_service.h" #import "chrome/browser/ui/cocoa/confirm_bubble_controller.h" +#include "chrome/browser/ui/confirm_bubble.h" #include "chrome/browser/ui/confirm_bubble_model.h" #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" #include "ui/gfx/image/image.h" @@ -49,9 +50,11 @@ const int kButtonHEdgeMargin = 7; } // namespace -void ConfirmBubbleModel::Show(gfx::NativeView view, - const gfx::Point& origin, - ConfirmBubbleModel* model) { +namespace browser { + +void ShowConfirmBubble(gfx::NativeView view, + const gfx::Point& origin, + ConfirmBubbleModel* model) { // Create a custom NSViewController that manages a bubble view, and add it to // a child to the specified view. This controller will be automatically // deleted when it loses first-responder status. @@ -65,13 +68,16 @@ void ConfirmBubbleModel::Show(gfx::NativeView view, [[view window] makeFirstResponder:[controller view]]; } +} // namespace browser + // An interface that is derived from NSTextView and does not accept // first-responder status, i.e. a NSTextView-derived class that never becomes // the first responder. When we click a NSTextView object, it becomes the first -// responder. Unfortunately, we delete the ConfirmBubbleView object anytime when -// it loses first-responder status not to prevent disturbing other responders. -// To prevent text views in this ConfirmBubbleView object from stealing the -// first-responder status, we use this view in the ConfirmBubbleView object. +// responder. Unfortunately, we delete the ConfirmBubbleCocoa object anytime +// when it loses first-responder status not to prevent disturbing other +// responders. +// To prevent text views in this ConfirmBubbleCocoa object from stealing the +// first-responder status, we use this view in the ConfirmBubbleCocoa object. @interface ConfirmBubbleTextView : NSTextView @end @@ -84,12 +90,12 @@ void ConfirmBubbleModel::Show(gfx::NativeView view, @end // Private Methods -@interface ConfirmBubbleView (Private) +@interface ConfirmBubbleCocoa (Private) - (void)performLayout; - (void)closeBubble; @end -@implementation ConfirmBubbleView +@implementation ConfirmBubbleCocoa - (id)initWithParent:(NSView*)parent controller:(ConfirmBubbleController*)controller { @@ -281,7 +287,7 @@ void ConfirmBubbleModel::Show(gfx::NativeView view, @end -@implementation ConfirmBubbleView (ExposedForUnitTesting) +@implementation ConfirmBubbleCocoa (ExposedForUnitTesting) - (void)clickOk { [self ok:self]; diff --git a/chrome/browser/ui/cocoa/confirm_bubble_controller.h b/chrome/browser/ui/cocoa/confirm_bubble_controller.h index 16f1725..ca58fa8 100644 --- a/chrome/browser/ui/cocoa/confirm_bubble_controller.h +++ b/chrome/browser/ui/cocoa/confirm_bubble_controller.h @@ -15,8 +15,7 @@ class ConfirmBubbleModel; // A view controller that manages a bubble view and becomes a proxy between // the view and the ConfirmBubbleModel object. This class is internally used -// in ConfirmBubbleView::Show() and users do not have to change this class -// directly. +// in ShowConfirmBubble() and users do not have to change this class directly. @interface ConfirmBubbleController : NSViewController<NSTextViewDelegate> { @private @@ -44,7 +43,7 @@ class ConfirmBubbleModel; - (BOOL)hasCancelButton; - (NSImage*)icon; -// Handle actions from from the ConfirmBubbleView objet. +// Handle actions from the ConfirmBubbleCocoa objet. - (void)accept; - (void)cancel; - (void)linkClicked; diff --git a/chrome/browser/ui/cocoa/confirm_bubble_controller.mm b/chrome/browser/ui/cocoa/confirm_bubble_controller.mm index 022e40b..4e45d10 100644 --- a/chrome/browser/ui/cocoa/confirm_bubble_controller.mm +++ b/chrome/browser/ui/cocoa/confirm_bubble_controller.mm @@ -6,7 +6,7 @@ #include "base/mac/mac_util.h" #include "base/sys_string_conversions.h" -#import "chrome/browser/ui/cocoa/confirm_bubble_view.h" +#import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h" #import "chrome/browser/ui/confirm_bubble_model.h" #include "ui/gfx/image/image.h" #include "ui/gfx/point.h" @@ -25,8 +25,8 @@ } - (void)loadView { - [self setView:[[[ConfirmBubbleView alloc] initWithParent:parent_ - controller:self] autorelease]]; + [self setView:[[[ConfirmBubbleCocoa alloc] initWithParent:parent_ + controller:self] autorelease]]; } - (void)windowWillClose:(NSNotification*)notification { diff --git a/chrome/browser/ui/cocoa/confirm_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/confirm_bubble_controller_unittest.mm index 2fd4e7c..5e64744 100644 --- a/chrome/browser/ui/cocoa/confirm_bubble_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/confirm_bubble_controller_unittest.mm @@ -8,8 +8,8 @@ #include "base/string16.h" #include "base/utf_string_conversions.h" #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" +#import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h" #import "chrome/browser/ui/cocoa/confirm_bubble_controller.h" -#import "chrome/browser/ui/cocoa/confirm_bubble_view.h" #include "chrome/browser/ui/confirm_bubble_model.h" #include "grit/theme_resources.h" #import "testing/gtest_mac.h" @@ -121,8 +121,8 @@ class ConfirmBubbleControllerTest : public CocoaTest { relativeTo:nil]; } - ConfirmBubbleView* GetBubbleView() const { - return (ConfirmBubbleView*)[controller_ view]; + ConfirmBubbleCocoa* GetBubble() const { + return (ConfirmBubbleCocoa*)[controller_ view]; } TestConfirmBubbleModel* model() const { return model_; } @@ -140,19 +140,19 @@ class ConfirmBubbleControllerTest : public CocoaTest { bool link_clicked_; }; -// Verify clicking a button or a link removes the ConfirmBubbleView object and +// Verify clicking a button or a link removes the ConfirmBubbleCocoa object and // calls an appropriate model method. TEST_F(ConfirmBubbleControllerTest, ClickOk) { NSView* view = [test_window() contentView]; - ConfirmBubbleView* bubble_view = GetBubbleView(); - bool contains_bubble_view = [[view subviews] containsObject:bubble_view]; + ConfirmBubbleCocoa* bubble = GetBubble(); + bool contains_bubble_view = [[view subviews] containsObject:bubble]; EXPECT_TRUE(contains_bubble_view); // Click its OK button and verify this view has been removed from the test // window. Also verify TestConfirmBubbleModel::Accept() has been called. - [bubble_view clickOk]; + [bubble clickOk]; - contains_bubble_view = [[view subviews] containsObject:bubble_view]; + contains_bubble_view = [[view subviews] containsObject:bubble]; EXPECT_FALSE(contains_bubble_view); EXPECT_TRUE(accept_clicked()); EXPECT_FALSE(cancel_clicked()); @@ -161,15 +161,15 @@ TEST_F(ConfirmBubbleControllerTest, ClickOk) { TEST_F(ConfirmBubbleControllerTest, ClickCancel) { NSView* view = [test_window() contentView]; - ConfirmBubbleView* bubble_view = GetBubbleView(); - bool contains_bubble_view = [[view subviews] containsObject:bubble_view]; + ConfirmBubbleCocoa* bubble = GetBubble(); + bool contains_bubble_view = [[view subviews] containsObject:bubble]; EXPECT_TRUE(contains_bubble_view); // Click its cancel button and verify this view has been removed from the test // window. Also verify TestConfirmBubbleModel::Cancel() has been called. - [bubble_view clickCancel]; + [bubble clickCancel]; - contains_bubble_view = [[view subviews] containsObject:bubble_view]; + contains_bubble_view = [[view subviews] containsObject:bubble]; EXPECT_FALSE(contains_bubble_view); EXPECT_FALSE(accept_clicked()); EXPECT_TRUE(cancel_clicked()); @@ -178,15 +178,15 @@ TEST_F(ConfirmBubbleControllerTest, ClickCancel) { TEST_F(ConfirmBubbleControllerTest, ClickLink) { NSView* view = [test_window() contentView]; - ConfirmBubbleView* bubble_view = GetBubbleView(); - bool contains_bubble_view = [[view subviews] containsObject:bubble_view]; + ConfirmBubbleCocoa* bubble = GetBubble(); + bool contains_bubble_view = [[view subviews] containsObject:bubble]; EXPECT_TRUE(contains_bubble_view); // Click its link and verify this view has been removed from the test window. // Also verify TestConfirmBubbleModel::LinkClicked() has been called. - [bubble_view clickLink]; + [bubble clickLink]; - contains_bubble_view = [[view subviews] containsObject:bubble_view]; + contains_bubble_view = [[view subviews] containsObject:bubble]; EXPECT_FALSE(contains_bubble_view); EXPECT_FALSE(accept_clicked()); EXPECT_FALSE(cancel_clicked()); diff --git a/chrome/browser/ui/confirm_bubble.h b/chrome/browser/ui/confirm_bubble.h new file mode 100644 index 0000000..9b6ca25 --- /dev/null +++ b/chrome/browser/ui/confirm_bubble.h @@ -0,0 +1,28 @@ +// Copyright (c) 2012 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_CONFIRM_BUBBLE_H_ +#define CHROME_BROWSER_UI_CONFIRM_BUBBLE_H_ +#pragma once + +#include "ui/gfx/native_widget_types.h" + +class ConfirmBubbleModel; + +namespace gfx { +class Point; +} + +namespace browser { + +// Creates a bubble and shows it with its top center at the specified +// |origin|. A bubble created by this function takes ownership of the +// specified |model|. +void ShowConfirmBubble(gfx::NativeView view, + const gfx::Point& origin, + ConfirmBubbleModel* model); + +} // namespace browser + +#endif // CHROME_BROWSER_UI_CONFIRM_BUBBLE_H_ diff --git a/chrome/browser/ui/confirm_bubble_model.h b/chrome/browser/ui/confirm_bubble_model.h index 4253c38..a7f3001 100644 --- a/chrome/browser/ui/confirm_bubble_model.h +++ b/chrome/browser/ui/confirm_bubble_model.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -8,17 +8,15 @@ #include "base/basictypes.h" #include "base/string16.h" -#include "ui/gfx/native_widget_types.h" namespace gfx { class Image; -class Point; } // An interface implemented by objects wishing to control an ConfirmBubbleView. // To use this class to implement a bubble menu, we need two steps: // 1. Implement a class derived from this class. -// 2. Call ConfirmBubbleModel::Show() with the class implemented in 1. +// 2. Call browser::ShowConfirmBubble() with the class implemented in 1. class ConfirmBubbleModel { public: enum BubbleButton { @@ -63,13 +61,6 @@ class ConfirmBubbleModel { // Called when the Link is clicked. virtual void LinkClicked(); - // Creates a bubble and shows it with its top center at the specified - // |origin|. A bubble created by this function takes ownership of the - // specified |model|. - static void Show(gfx::NativeView view, - const gfx::Point& origin, - ConfirmBubbleModel* model); - private: DISALLOW_COPY_AND_ASSIGN(ConfirmBubbleModel); }; diff --git a/chrome/browser/ui/gtk/confirm_bubble_view.cc b/chrome/browser/ui/gtk/confirm_bubble_gtk.cc index a4d2d14..d3e50d1 100644 --- a/chrome/browser/ui/gtk/confirm_bubble_view.cc +++ b/chrome/browser/ui/gtk/confirm_bubble_gtk.cc @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/gtk/confirm_bubble_view.h" +#include "chrome/browser/ui/gtk/confirm_bubble_gtk.h" #include <gtk/gtk.h> #include "base/logging.h" #include "base/utf_string_conversions.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/confirm_bubble.h" #include "chrome/browser/ui/confirm_bubble_model.h" #include "chrome/browser/ui/gtk/browser_window_gtk.h" #include "chrome/browser/ui/gtk/custom_button.h" @@ -41,16 +42,9 @@ const int kMaxMessageWidth = 400; } // namespace -void ConfirmBubbleModel::Show(gfx::NativeView view, - const gfx::Point& origin, - ConfirmBubbleModel* model) { - ConfirmBubbleView* bubble_view = new ConfirmBubbleView(view, origin, model); - bubble_view->Show(); -} - -ConfirmBubbleView::ConfirmBubbleView(gfx::NativeView anchor, - const gfx::Point& anchor_point, - ConfirmBubbleModel* model) +ConfirmBubbleGtk::ConfirmBubbleGtk(gfx::NativeView anchor, + const gfx::Point& anchor_point, + ConfirmBubbleModel* model) : bubble_(NULL), anchor_(anchor), anchor_point_(anchor_point), @@ -58,14 +52,14 @@ ConfirmBubbleView::ConfirmBubbleView(gfx::NativeView anchor, DCHECK(model); } -ConfirmBubbleView::~ConfirmBubbleView() { +ConfirmBubbleGtk::~ConfirmBubbleGtk() { } -void ConfirmBubbleView::BubbleClosing(BubbleGtk* bubble, - bool closed_by_escape) { +void ConfirmBubbleGtk::BubbleClosing(BubbleGtk* bubble, + bool closed_by_escape) { } -void ConfirmBubbleView::Show() { +void ConfirmBubbleGtk::Show() { GtkWidget* toplevel = gtk_widget_get_toplevel(anchor_); BrowserWindowGtk* browser_window = BrowserWindowGtk::GetBrowserWindowForNativeWindow(GTK_WINDOW(toplevel)); @@ -153,33 +147,44 @@ void ConfirmBubbleView::Show() { this); // error } -void ConfirmBubbleView::OnDestroy(GtkWidget* sender) { +void ConfirmBubbleGtk::OnDestroy(GtkWidget* sender) { // TODO(hbono): this code prevents the model from updating this view when we // click buttons. We should ask the model if we can delete this view. delete this; } -void ConfirmBubbleView::OnCloseButton(GtkWidget* sender) { +void ConfirmBubbleGtk::OnCloseButton(GtkWidget* sender) { bubble_->Close(); } -void ConfirmBubbleView::OnOkButton(GtkWidget* sender) { +void ConfirmBubbleGtk::OnOkButton(GtkWidget* sender) { model_->Accept(); // TODO(hbono): this code prevents the model from updating this view when we // click this button. We should ask the model if we can close this view. bubble_->Close(); } -void ConfirmBubbleView::OnCancelButton(GtkWidget* sender) { +void ConfirmBubbleGtk::OnCancelButton(GtkWidget* sender) { model_->Cancel(); // TODO(hbono): this code prevents the model from updating this view when we // click this button. We should ask the model if we can close this view. bubble_->Close(); } -void ConfirmBubbleView::OnLinkButton(GtkWidget* sender) { +void ConfirmBubbleGtk::OnLinkButton(GtkWidget* sender) { model_->LinkClicked(); // TODO(hbono): this code prevents the model from updating this view when we // click this link. We should ask the model if we can close this view. bubble_->Close(); } + +namespace browser { + +void ShowConfirmBubble(gfx::NativeView view, + const gfx::Point& origin, + ConfirmBubbleModel* model) { + ConfirmBubbleGtk* bubble = new ConfirmBubbleGtk(view, origin, model); + bubble->Show(); +} + +} // namespace browser diff --git a/chrome/browser/ui/gtk/confirm_bubble_view.h b/chrome/browser/ui/gtk/confirm_bubble_gtk.h index 2414411..129898c 100644 --- a/chrome/browser/ui/gtk/confirm_bubble_view.h +++ b/chrome/browser/ui/gtk/confirm_bubble_gtk.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_GTK_CONFIRM_BUBBLE_VIEW_H_ -#define CHROME_BROWSER_UI_GTK_CONFIRM_BUBBLE_VIEW_H_ +#ifndef CHROME_BROWSER_UI_GTK_CONFIRM_BUBBLE_GTK_H_ +#define CHROME_BROWSER_UI_GTK_CONFIRM_BUBBLE_GTK_H_ #pragma once #include "base/compiler_specific.h" @@ -38,12 +38,12 @@ class CustomDrawButton; // | [Cancel] [OK] | // +------------------------+ // -class ConfirmBubbleView : public BubbleDelegateGtk { +class ConfirmBubbleGtk : public BubbleDelegateGtk { public: - ConfirmBubbleView(gfx::NativeView parent, - const gfx::Point& anchor_point, - ConfirmBubbleModel* model); - virtual ~ConfirmBubbleView(); + ConfirmBubbleGtk(gfx::NativeView parent, + const gfx::Point& anchor_point, + ConfirmBubbleModel* model); + virtual ~ConfirmBubbleGtk(); // BubbleDelegateGtk implementation. virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE; @@ -52,16 +52,16 @@ class ConfirmBubbleView : public BubbleDelegateGtk { void Show(); private: - FRIEND_TEST_ALL_PREFIXES(ConfirmBubbleViewTest, ClickCancel); - FRIEND_TEST_ALL_PREFIXES(ConfirmBubbleViewTest, ClickOk); - FRIEND_TEST_ALL_PREFIXES(ConfirmBubbleViewTest, ClickLink); + FRIEND_TEST_ALL_PREFIXES(ConfirmBubbleGtkTest, ClickCancel); + FRIEND_TEST_ALL_PREFIXES(ConfirmBubbleGtkTest, ClickOk); + FRIEND_TEST_ALL_PREFIXES(ConfirmBubbleGtkTest, ClickLink); // GTK event handlers. - CHROMEGTK_CALLBACK_0(ConfirmBubbleView, void, OnDestroy); - CHROMEGTK_CALLBACK_0(ConfirmBubbleView, void, OnCloseButton); - CHROMEGTK_CALLBACK_0(ConfirmBubbleView, void, OnOkButton); - CHROMEGTK_CALLBACK_0(ConfirmBubbleView, void, OnCancelButton); - CHROMEGTK_CALLBACK_0(ConfirmBubbleView, void, OnLinkButton); + CHROMEGTK_CALLBACK_0(ConfirmBubbleGtk, void, OnDestroy); + CHROMEGTK_CALLBACK_0(ConfirmBubbleGtk, void, OnCloseButton); + CHROMEGTK_CALLBACK_0(ConfirmBubbleGtk, void, OnOkButton); + CHROMEGTK_CALLBACK_0(ConfirmBubbleGtk, void, OnCancelButton); + CHROMEGTK_CALLBACK_0(ConfirmBubbleGtk, void, OnLinkButton); // The bubble. BubbleGtk* bubble_; @@ -77,7 +77,7 @@ class ConfirmBubbleView : public BubbleDelegateGtk { // The x that closes this bubble. scoped_ptr<CustomDrawButton> close_button_; - DISALLOW_COPY_AND_ASSIGN(ConfirmBubbleView); + DISALLOW_COPY_AND_ASSIGN(ConfirmBubbleGtk); }; -#endif // CHROME_BROWSER_UI_GTK_CONFIRM_BUBBLE_VIEW_H_ +#endif // CHROME_BROWSER_UI_GTK_CONFIRM_BUBBLE_GTK_H_ diff --git a/chrome/browser/ui/gtk/confirm_bubble_view_browsertest.cc b/chrome/browser/ui/gtk/confirm_bubble_gtk_browsertest.cc index 18457d8..7a44ac6 100644 --- a/chrome/browser/ui/gtk/confirm_bubble_view_browsertest.cc +++ b/chrome/browser/ui/gtk/confirm_bubble_gtk_browsertest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/ui/gtk/confirm_bubble_gtk.h" + #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/string16.h" @@ -9,7 +11,6 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/confirm_bubble_model.h" -#include "chrome/browser/ui/gtk/confirm_bubble_view.h" #include "chrome/test/base/in_process_browser_test.h" #include "grit/theme_resources.h" #include "ui/base/resource/resource_bundle.h" @@ -17,7 +18,7 @@ namespace { // The model object used in this test. This model implements all methods and -// updates its status when ConfirmBubbleView calls its methods. +// updates its status when ConfirmBubbleGtk calls its methods. class TestConfirmBubbleModel : public ConfirmBubbleModel { public: TestConfirmBubbleModel(bool* model_deleted, @@ -95,10 +96,10 @@ void TestConfirmBubbleModel::LinkClicked() { } // namespace -class ConfirmBubbleViewTest : public InProcessBrowserTest { +class ConfirmBubbleGtkTest : public InProcessBrowserTest { public: - ConfirmBubbleViewTest() - : view_(NULL), + ConfirmBubbleGtkTest() + : bubble_(NULL), model_deleted_(false), accept_clicked_(false), cancel_clicked_(false), @@ -112,19 +113,17 @@ class ConfirmBubbleViewTest : public InProcessBrowserTest { link_clicked_ = false; gfx::Point point(0, 0); - view_ = new ConfirmBubbleView( + bubble_ = new ConfirmBubbleGtk( GTK_WIDGET(browser()->window()->GetNativeHandle()), point, new TestConfirmBubbleModel(&model_deleted_, &accept_clicked_, &cancel_clicked_, &link_clicked_)); - view_->Show(); + bubble_->Show(); } - ConfirmBubbleView* view() const { - return view_; - } + ConfirmBubbleGtk* bubble() const { return bubble_; } bool model_deleted() const { return model_deleted_; @@ -143,7 +142,7 @@ class ConfirmBubbleViewTest : public InProcessBrowserTest { } private: - ConfirmBubbleView* view_; + ConfirmBubbleGtk* bubble_; bool model_deleted_; bool accept_clicked_; bool cancel_clicked_; @@ -152,9 +151,9 @@ class ConfirmBubbleViewTest : public InProcessBrowserTest { // Verifies clicking a button or a link calls an appropriate model method and // deletes the model. -IN_PROC_BROWSER_TEST_F(ConfirmBubbleViewTest, ClickCancel) { +IN_PROC_BROWSER_TEST_F(ConfirmBubbleGtkTest, ClickCancel) { ShowBubble(); - view()->OnCancelButton(NULL); + bubble()->OnCancelButton(NULL); EXPECT_TRUE(model_deleted()); EXPECT_FALSE(accept_clicked()); @@ -162,9 +161,9 @@ IN_PROC_BROWSER_TEST_F(ConfirmBubbleViewTest, ClickCancel) { EXPECT_FALSE(link_clicked()); } -IN_PROC_BROWSER_TEST_F(ConfirmBubbleViewTest, ClickLink) { +IN_PROC_BROWSER_TEST_F(ConfirmBubbleGtkTest, ClickLink) { ShowBubble(); - view()->OnLinkButton(NULL); + bubble()->OnLinkButton(NULL); EXPECT_TRUE(model_deleted()); EXPECT_FALSE(accept_clicked()); @@ -172,9 +171,9 @@ IN_PROC_BROWSER_TEST_F(ConfirmBubbleViewTest, ClickLink) { EXPECT_TRUE(link_clicked()); } -IN_PROC_BROWSER_TEST_F(ConfirmBubbleViewTest, ClickOk) { +IN_PROC_BROWSER_TEST_F(ConfirmBubbleGtkTest, ClickOk) { ShowBubble(); - view()->OnOkButton(NULL); + bubble()->OnOkButton(NULL); EXPECT_TRUE(model_deleted()); EXPECT_TRUE(accept_clicked()); diff --git a/chrome/browser/ui/views/confirm_bubble_view.cc b/chrome/browser/ui/views/confirm_bubble_views.cc index 21655cb..47610e9 100644 --- a/chrome/browser/ui/views/confirm_bubble_view.cc +++ b/chrome/browser/ui/views/confirm_bubble_views.cc @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/views/confirm_bubble_view.h" +#include "chrome/browser/ui/views/confirm_bubble_views.h" +#include "chrome/browser/ui/confirm_bubble.h" #include "chrome/browser/ui/confirm_bubble_model.h" #include "grit/theme_resources.h" #include "ui/base/resource/resource_bundle.h" @@ -24,27 +25,19 @@ const int kMaxMessageWidth = 400; } // namespace -void ConfirmBubbleModel::Show(gfx::NativeView view, - const gfx::Point& origin, - ConfirmBubbleModel* model) { - ConfirmBubbleView* bubble_view = new ConfirmBubbleView(origin, model); - views::BubbleDelegateView::CreateBubble(bubble_view); - bubble_view->Show(); -} - -ConfirmBubbleView::ConfirmBubbleView(const gfx::Point& anchor_point, - ConfirmBubbleModel* model) +ConfirmBubbleViews::ConfirmBubbleViews(const gfx::Point& anchor_point, + ConfirmBubbleModel* model) : BubbleDelegateView(NULL, views::BubbleBorder::NONE), anchor_point_(anchor_point), model_(model) { DCHECK(model); } -ConfirmBubbleView::~ConfirmBubbleView() { +ConfirmBubbleViews::~ConfirmBubbleViews() { } -void ConfirmBubbleView::ButtonPressed(views::Button* sender, - const views::Event& event) { +void ConfirmBubbleViews::ButtonPressed(views::Button* sender, + const views::Event& event) { if (sender->tag() == ConfirmBubbleModel::BUTTON_OK) model_->Accept(); else if (sender->tag() == ConfirmBubbleModel::BUTTON_CANCEL) @@ -52,15 +45,15 @@ void ConfirmBubbleView::ButtonPressed(views::Button* sender, GetWidget()->Close(); } -void ConfirmBubbleView::LinkClicked(views::Link* source, int event_flags) { +void ConfirmBubbleViews::LinkClicked(views::Link* source, int event_flags) { model_->LinkClicked(); } -gfx::Rect ConfirmBubbleView::GetAnchorRect() { +gfx::Rect ConfirmBubbleViews::GetAnchorRect() { return gfx::Rect(anchor_point_, gfx::Size()); } -void ConfirmBubbleView::Init() { +void ConfirmBubbleViews::Init() { ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); views::GridLayout* layout = new views::GridLayout(this); SetLayoutManager(layout); @@ -156,3 +149,15 @@ void ConfirmBubbleView::Init() { } } } + +namespace browser { + +void ShowConfirmBubble(gfx::NativeView view, + const gfx::Point& origin, + ConfirmBubbleModel* model) { + ConfirmBubbleViews* bubble = new ConfirmBubbleViews(origin, model); + views::BubbleDelegateView::CreateBubble(bubble); + bubble->Show(); +} + +} // namespace browser diff --git a/chrome/browser/ui/views/confirm_bubble_view.h b/chrome/browser/ui/views/confirm_bubble_views.h index 6a03491..d416a59 100644 --- a/chrome/browser/ui/views/confirm_bubble_view.h +++ b/chrome/browser/ui/views/confirm_bubble_views.h @@ -1,9 +1,9 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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_CONFIRM_BUBBLE_VIEW_H_ -#define CHROME_BROWSER_UI_VIEWS_CONFIRM_BUBBLE_VIEW_H_ +#ifndef CHROME_BROWSER_UI_VIEWS_CONFIRM_BUBBLE_VIEWS_H_ +#define CHROME_BROWSER_UI_VIEWS_CONFIRM_BUBBLE_VIEWS_H_ #pragma once #include "base/compiler_specific.h" @@ -33,15 +33,15 @@ class ConfirmBubbleModel; // | [OK] [Cancel] | // +------------------------+ // -class ConfirmBubbleView : public views::BubbleDelegateView, - public views::ButtonListener, - public views::LinkListener { +class ConfirmBubbleViews : public views::BubbleDelegateView, + public views::ButtonListener, + public views::LinkListener { public: - explicit ConfirmBubbleView(const gfx::Point& anchor_point, - ConfirmBubbleModel* model); + explicit ConfirmBubbleViews(const gfx::Point& anchor_point, + ConfirmBubbleModel* model); protected: - virtual ~ConfirmBubbleView(); + virtual ~ConfirmBubbleViews(); // views::ButtonListener implementation. virtual void ButtonPressed(views::Button* sender, @@ -61,7 +61,7 @@ class ConfirmBubbleView : public views::BubbleDelegateView, // The model to customize this bubble view. scoped_ptr<ConfirmBubbleModel> model_; - DISALLOW_COPY_AND_ASSIGN(ConfirmBubbleView); + DISALLOW_COPY_AND_ASSIGN(ConfirmBubbleViews); }; -#endif // CHROME_BROWSER_UI_VIEWS_CONFIRM_BUBBLE_VIEW_H_ +#endif // CHROME_BROWSER_UI_VIEWS_CONFIRM_BUBBLE_VIEWS_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index b9ca6c2..588111e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2454,8 +2454,8 @@ 'browser/ui/cocoa/command_observer_bridge.mm', 'browser/ui/cocoa/confirm_bubble_controller.h', 'browser/ui/cocoa/confirm_bubble_controller.mm', - 'browser/ui/cocoa/confirm_bubble_view.h', - 'browser/ui/cocoa/confirm_bubble_view.mm', + 'browser/ui/cocoa/confirm_bubble_cocoa.h', + 'browser/ui/cocoa/confirm_bubble_cocoa.mm', 'browser/ui/cocoa/confirm_quit.h', 'browser/ui/cocoa/confirm_quit_panel_controller.h', 'browser/ui/cocoa/confirm_quit_panel_controller.mm', @@ -2793,6 +2793,7 @@ 'browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm', 'browser/ui/collected_cookies_infobar_delegate.cc', 'browser/ui/collected_cookies_infobar_delegate.h', + 'browser/ui/confirm_bubble.h', 'browser/ui/confirm_bubble_model.cc', 'browser/ui/confirm_bubble_model.h', 'browser/ui/content_settings/content_setting_bubble_model.cc', @@ -2891,8 +2892,8 @@ 'browser/ui/gtk/chrome_to_mobile_bubble_gtk.h', 'browser/ui/gtk/collected_cookies_gtk.cc', 'browser/ui/gtk/collected_cookies_gtk.h', - 'browser/ui/gtk/confirm_bubble_view.cc', - 'browser/ui/gtk/confirm_bubble_view.h', + 'browser/ui/gtk/confirm_bubble_gtk.cc', + 'browser/ui/gtk/confirm_bubble_gtk.h', 'browser/ui/gtk/color_chooser_gtk.cc', 'browser/ui/gtk/constrained_web_dialog_delegate_gtk.cc', 'browser/ui/gtk/constrained_window_gtk.cc', @@ -3379,8 +3380,8 @@ 'browser/ui/views/chrome_views_delegate.h', 'browser/ui/views/collected_cookies_views.cc', 'browser/ui/views/collected_cookies_views.h', - 'browser/ui/views/confirm_bubble_view.cc', - 'browser/ui/views/confirm_bubble_view.h', + 'browser/ui/views/confirm_bubble_views.cc', + 'browser/ui/views/confirm_bubble_views.h', 'browser/ui/views/constrained_web_dialog_delegate_views.cc', 'browser/ui/views/constrained_window_views.cc', 'browser/ui/views/constrained_window_views.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index a307906..15782e6 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -3212,7 +3212,7 @@ 'sources': [ # BubbleGtk is used only on Linux/GTK. 'browser/ui/gtk/bubble/bubble_gtk_browsertest.cc', - 'browser/ui/gtk/confirm_bubble_view_browsertest.cc', + 'browser/ui/gtk/confirm_bubble_gtk_browsertest.cc', ], }], ['OS=="mac"', { |