Commit 49f9a7a9 authored by andresantoso's avatar andresantoso Committed by Commit bot

MacViews: Fix duplicate definition of ValidationMessageBubble::ShowAndCreate

Refactor into a virtual method on TabDialogs, with overrides for Views and
Cocoa.
ValidationMessageBubble is moved out of chrome namespace to be more
consistent with other dialogs.

BUG=425229

Review URL: https://codereview.chromium.org/867323005

Cr-Commit-Position: refs/heads/master@{#313411}
parent 61da3cc6
...@@ -1213,15 +1213,9 @@ void Browser::ShowValidationMessage(content::WebContents* web_contents, ...@@ -1213,15 +1213,9 @@ void Browser::ShowValidationMessage(content::WebContents* web_contents,
const gfx::Rect& anchor_in_root_view, const gfx::Rect& anchor_in_root_view,
const base::string16& main_text, const base::string16& main_text,
const base::string16& sub_text) { const base::string16& sub_text) {
RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); validation_message_bubble_ =
if (rwhv) { TabDialogs::FromWebContents(web_contents)
validation_message_bubble_ = ->ShowValidationMessage(anchor_in_root_view, main_text, sub_text);
chrome::ValidationMessageBubble::CreateAndShow(
rwhv->GetRenderWidgetHost(),
anchor_in_root_view,
main_text,
sub_text);
}
} }
void Browser::HideValidationMessage(content::WebContents* web_contents) { void Browser::HideValidationMessage(content::WebContents* web_contents) {
......
...@@ -65,13 +65,13 @@ class SearchModel; ...@@ -65,13 +65,13 @@ class SearchModel;
class StatusBubble; class StatusBubble;
class TabStripModel; class TabStripModel;
class TabStripModelDelegate; class TabStripModelDelegate;
class ValidationMessageBubble;
struct WebApplicationInfo; struct WebApplicationInfo;
namespace chrome { namespace chrome {
class BrowserCommandController; class BrowserCommandController;
class FastUnloadController; class FastUnloadController;
class UnloadController; class UnloadController;
class ValidationMessageBubble;
} }
namespace content { namespace content {
...@@ -965,7 +965,7 @@ class Browser : public TabStripModelObserver, ...@@ -965,7 +965,7 @@ class Browser : public TabStripModelObserver,
scoped_ptr<BrowserContentTranslateDriverObserver> translate_driver_observer_; scoped_ptr<BrowserContentTranslateDriverObserver> translate_driver_observer_;
scoped_ptr<chrome::ValidationMessageBubble> validation_message_bubble_; scoped_ptr<ValidationMessageBubble> validation_message_bubble_;
// The following factory is used for chrome update coalescing. // The following factory is used for chrome update coalescing.
base::WeakPtrFactory<Browser> chrome_updater_factory_; base::WeakPtrFactory<Browser> chrome_updater_factory_;
......
...@@ -24,6 +24,10 @@ class TabDialogsCocoa : public TabDialogs { ...@@ -24,6 +24,10 @@ class TabDialogsCocoa : public TabDialogs {
ui::ProfileSigninConfirmationDelegate* delegate) override; ui::ProfileSigninConfirmationDelegate* delegate) override;
void ShowManagePasswordsBubble(bool user_action) override; void ShowManagePasswordsBubble(bool user_action) override;
void HideManagePasswordsBubble() override; void HideManagePasswordsBubble() override;
scoped_ptr<ValidationMessageBubble> ShowValidationMessage(
const gfx::Rect& anchor_in_root_view,
const base::string16& main_text,
const base::string16& sub_text) override;
private: private:
content::WebContents* web_contents_; // Weak. Owns this. content::WebContents* web_contents_; // Weak. Owns this.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "chrome/browser/ui/cocoa/hung_renderer_controller.h" #import "chrome/browser/ui/cocoa/hung_renderer_controller.h"
#import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.h" #import "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.h"
#import "chrome/browser/ui/cocoa/profiles/profile_signin_confirmation_dialog_cocoa.h" #import "chrome/browser/ui/cocoa/profiles/profile_signin_confirmation_dialog_cocoa.h"
#import "chrome/browser/ui/cocoa/validation_message_bubble_cocoa.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
// static // static
...@@ -54,3 +55,11 @@ void TabDialogsCocoa::ShowManagePasswordsBubble(bool user_action) { ...@@ -54,3 +55,11 @@ void TabDialogsCocoa::ShowManagePasswordsBubble(bool user_action) {
void TabDialogsCocoa::HideManagePasswordsBubble() { void TabDialogsCocoa::HideManagePasswordsBubble() {
// The bubble is closed when it loses the focus. // The bubble is closed when it loses the focus.
} }
scoped_ptr<ValidationMessageBubble> TabDialogsCocoa::ShowValidationMessage(
const gfx::Rect& anchor_in_root_view,
const base::string16& main_text,
const base::string16& sub_text) {
return make_scoped_ptr(new ValidationMessageBubbleCocoa(
web_contents_, anchor_in_root_view, main_text, sub_text));
}
// Copyright 2015 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_COCOA_VALIDATION_MESSAGE_BUBBLE_COCOA_H_
#define CHROME_BROWSER_UI_COCOA_VALIDATION_MESSAGE_BUBBLE_COCOA_H_
#include "base/mac/scoped_nsobject.h"
#include "chrome/browser/ui/validation_message_bubble.h"
@class ValidationMessageBubbleController;
namespace content {
class WebContents;
}
class ValidationMessageBubbleCocoa : public ValidationMessageBubble {
public:
ValidationMessageBubbleCocoa(content::WebContents* web_contents,
const gfx::Rect& anchor_in_root_view,
const base::string16& main_text,
const base::string16& sub_text);
~ValidationMessageBubbleCocoa() override;
// ValidationMessageBubble overrides:
void SetPositionRelativeToAnchor(
content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_root_view) override;
private:
base::scoped_nsobject<ValidationMessageBubbleController> controller_;
DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleCocoa);
};
#endif // CHROME_BROWSER_UI_COCOA_VALIDATION_MESSAGE_BUBBLE_COCOA_H_
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/cocoa/validation_message_bubble_cocoa.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -9,8 +11,9 @@ ...@@ -9,8 +11,9 @@
#import "chrome/browser/ui/cocoa/info_bubble_window.h" #import "chrome/browser/ui/cocoa/info_bubble_window.h"
#import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h" #import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h"
#include "chrome/browser/ui/validation_message_bubble.h" #include "chrome/browser/ui/validation_message_bubble.h"
#include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h" #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#import "ui/base/cocoa/base_view.h" #import "ui/base/cocoa/base_view.h"
...@@ -134,8 +137,6 @@ anchoredAt:(NSPoint)anchorPoint ...@@ -134,8 +137,6 @@ anchoredAt:(NSPoint)anchorPoint
// ---------------------------------------------------------------- // ----------------------------------------------------------------
namespace {
// Converts |anchor_in_root_view| in rwhv coordinates to cocoa screen // Converts |anchor_in_root_view| in rwhv coordinates to cocoa screen
// coordinates, and returns an NSPoint at the center of the bottom side of the // coordinates, and returns an NSPoint at the center of the bottom side of the
// converted rectangle. // converted rectangle.
...@@ -149,45 +150,25 @@ NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host, ...@@ -149,45 +150,25 @@ NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host,
return [[view window] convertBaseToScreen:point]; return [[view window] convertBaseToScreen:point];
} }
class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble { ValidationMessageBubbleCocoa::ValidationMessageBubbleCocoa(
public: content::WebContents* web_contents,
ValidationMessageBubbleCocoa(content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_root_view,
const base::string16& main_text,
const base::string16& sub_text) {
controller_.reset([[[ValidationMessageBubbleController alloc]
init:[widget_host->GetView()->GetNativeView() window]
anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view)
mainText:main_text
subText:sub_text] retain]);
}
~ValidationMessageBubbleCocoa() override { [controller_.get() close]; }
void SetPositionRelativeToAnchor(
content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_root_view) override {
[controller_.get()
setAnchorPoint:GetAnchorPoint(widget_host, anchor_in_root_view)];
}
private:
base::scoped_nsobject<ValidationMessageBubbleController> controller_;
};
}
// ----------------------------------------------------------------
namespace chrome {
scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow(
content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_root_view, const gfx::Rect& anchor_in_root_view,
const base::string16& main_text, const base::string16& main_text,
const base::string16& sub_text) { const base::string16& sub_text) {
return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleCocoa( content::RenderWidgetHost* widget_host = web_contents->GetRenderViewHost();
widget_host, anchor_in_root_view, main_text, sub_text)).Pass(); controller_.reset([[[ValidationMessageBubbleController alloc]
init:[widget_host->GetView()->GetNativeView() window]
anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view)
mainText:main_text
subText:sub_text] retain]);
}
ValidationMessageBubbleCocoa::~ValidationMessageBubbleCocoa() {
[controller_ close];
} }
void ValidationMessageBubbleCocoa::SetPositionRelativeToAnchor(
content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_root_view) {
[controller_ setAnchorPoint:GetAnchorPoint(widget_host, anchor_in_root_view)];
} }
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
#include <string> #include <string>
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/supports_user_data.h" #include "base/supports_user_data.h"
#include "chrome/browser/ui/validation_message_bubble.h"
class Browser; class Browser;
class Profile; class Profile;
...@@ -16,6 +19,10 @@ namespace content { ...@@ -16,6 +19,10 @@ namespace content {
class WebContents; class WebContents;
} }
namespace gfx {
class Rect;
}
namespace ui { namespace ui {
class ProfileSigninConfirmationDelegate; class ProfileSigninConfirmationDelegate;
} }
...@@ -52,6 +59,11 @@ class TabDialogs : public base::SupportsUserData::Data { ...@@ -52,6 +59,11 @@ class TabDialogs : public base::SupportsUserData::Data {
virtual void ShowManagePasswordsBubble(bool user_action) = 0; virtual void ShowManagePasswordsBubble(bool user_action) = 0;
virtual void HideManagePasswordsBubble() = 0; virtual void HideManagePasswordsBubble() = 0;
virtual scoped_ptr<ValidationMessageBubble> ShowValidationMessage(
const gfx::Rect& anchor_in_root_view,
const base::string16& main_text,
const base::string16& sub_text) = 0;
protected: protected:
static const void* UserDataKey(); static const void* UserDataKey();
}; };
......
...@@ -16,8 +16,6 @@ namespace gfx { ...@@ -16,8 +16,6 @@ namespace gfx {
class Rect; class Rect;
} }
namespace chrome {
class ValidationMessageBubble { class ValidationMessageBubble {
public: public:
// Open a tooltip-like window to show the specified messages. The window // Open a tooltip-like window to show the specified messages. The window
...@@ -39,6 +37,4 @@ class ValidationMessageBubble { ...@@ -39,6 +37,4 @@ class ValidationMessageBubble {
const gfx::Rect& anchor_in_root_view) = 0; const gfx::Rect& anchor_in_root_view) = 0;
}; };
} // namespace chrome
#endif // CHROME_BROWSER_UI_VALIDATION_MESSAGE_BUBBLE_H_ #endif // CHROME_BROWSER_UI_VALIDATION_MESSAGE_BUBBLE_H_
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/ui/views/hung_renderer_view.h" #include "chrome/browser/ui/views/hung_renderer_view.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
#include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.h" #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.h"
#include "chrome/browser/ui/views/validation_message_bubble_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
// static // static
...@@ -66,3 +67,11 @@ void TabDialogsViews::HideManagePasswordsBubble() { ...@@ -66,3 +67,11 @@ void TabDialogsViews::HideManagePasswordsBubble() {
if (web_contents_ == bubble_web_contents) if (web_contents_ == bubble_web_contents)
ManagePasswordsBubbleView::CloseBubble(); ManagePasswordsBubbleView::CloseBubble();
} }
scoped_ptr<ValidationMessageBubble> TabDialogsViews::ShowValidationMessage(
const gfx::Rect& anchor_in_root_view,
const base::string16& main_text,
const base::string16& sub_text) {
return make_scoped_ptr(new ValidationMessageBubbleView(
web_contents_, anchor_in_root_view, main_text, sub_text));
}
...@@ -25,6 +25,10 @@ class TabDialogsViews : public TabDialogs { ...@@ -25,6 +25,10 @@ class TabDialogsViews : public TabDialogs {
ui::ProfileSigninConfirmationDelegate* delegate) override; ui::ProfileSigninConfirmationDelegate* delegate) override;
void ShowManagePasswordsBubble(bool user_action) override; void ShowManagePasswordsBubble(bool user_action) override;
void HideManagePasswordsBubble() override; void HideManagePasswordsBubble() override;
scoped_ptr<ValidationMessageBubble> ShowValidationMessage(
const gfx::Rect& anchor_in_root_view,
const base::string16& main_text,
const base::string16& sub_text) override;
private: private:
content::WebContents* web_contents_; // Weak. Owns this. content::WebContents* web_contents_; // Weak. Owns this.
......
...@@ -2,76 +2,43 @@ ...@@ -2,76 +2,43 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/validation_message_bubble.h" #include "chrome/browser/ui/views/validation_message_bubble_view.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/views/validation_message_bubble_delegate.h"
#include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace { ValidationMessageBubbleView::ValidationMessageBubbleView(
content::WebContents* web_contents,
// A ValidationMessageBubble implementation for Views. const gfx::Rect& anchor_in_root_view,
class ValidationMessageBubbleImpl
: public chrome::ValidationMessageBubble,
public ValidationMessageBubbleDelegate::Observer {
public:
ValidationMessageBubbleImpl(content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_screen,
const base::string16& main_text,
const base::string16& sub_text);
~ValidationMessageBubbleImpl() override {
if (delegate_ != NULL)
delegate_->Close();
}
void SetPositionRelativeToAnchor(
content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_root_view) override {
if (!delegate_)
return;
delegate_->SetPositionRelativeToAnchor(anchor_in_root_view +
widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin());
}
// ValidationMessageBubbleDelegate::Observer override:
void WindowClosing() override { delegate_ = NULL; }
private:
ValidationMessageBubbleDelegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleImpl);
};
ValidationMessageBubbleImpl::ValidationMessageBubbleImpl(
content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_screen,
const base::string16& main_text, const base::string16& main_text,
const base::string16& sub_text) { const base::string16& sub_text) {
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
const gfx::Rect anchor_in_screen =
anchor_in_root_view + rwhv->GetViewBounds().origin().OffsetFromOrigin();
delegate_ = new ValidationMessageBubbleDelegate( delegate_ = new ValidationMessageBubbleDelegate(
anchor_in_screen, main_text, sub_text, this); anchor_in_screen, main_text, sub_text, this);
delegate_->set_parent_window(platform_util::GetTopLevel( delegate_->set_parent_window(rwhv->GetNativeView());
widget_host->GetView()->GetNativeView()));
views::BubbleDelegateView::CreateBubble(delegate_); views::BubbleDelegateView::CreateBubble(delegate_);
delegate_->GetWidget()->ShowInactive(); delegate_->GetWidget()->ShowInactive();
} }
} // namespace ValidationMessageBubbleView::~ValidationMessageBubbleView() {
if (delegate_)
namespace chrome { delegate_->Close();
}
scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( void ValidationMessageBubbleView::SetPositionRelativeToAnchor(
content::RenderWidgetHost* widget_host, content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_root_view, const gfx::Rect& anchor_in_root_view) {
const base::string16& main_text, if (!delegate_)
const base::string16& sub_text) { return;
const gfx::Rect anchor_in_screen = anchor_in_root_view delegate_->SetPositionRelativeToAnchor(
+ widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin(); anchor_in_root_view +
scoped_ptr<ValidationMessageBubble> bubble(new ValidationMessageBubbleImpl( widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin());
widget_host, anchor_in_screen, main_text, sub_text));
return bubble.Pass();
} }
} // namespace chrome void ValidationMessageBubbleView::WindowClosing() {
delegate_ = NULL;
}
// Copyright 2015 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_VALIDATION_MESSAGE_BUBBLE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_VALIDATION_MESSAGE_BUBBLE_VIEW_H_
#include "chrome/browser/ui/validation_message_bubble.h"
#include "chrome/browser/ui/views/validation_message_bubble_delegate.h"
namespace content {
class WebContents;
}
// A ValidationMessageBubble implementation for Views.
class ValidationMessageBubbleView
: public ValidationMessageBubble,
public ValidationMessageBubbleDelegate::Observer {
public:
ValidationMessageBubbleView(content::WebContents* web_contents,
const gfx::Rect& anchor_in_root_view,
const base::string16& main_text,
const base::string16& sub_text);
~ValidationMessageBubbleView() override;
// ValidationMessageBubble overrides:
void SetPositionRelativeToAnchor(
content::RenderWidgetHost* widget_host,
const gfx::Rect& anchor_in_root_view) override;
// ValidationMessageBubbleDelegate::Observer overrides:
void WindowClosing() override;
private:
ValidationMessageBubbleDelegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleView);
};
#endif // CHROME_BROWSER_UI_VIEWS_VALIDATION_MESSAGE_BUBBLE_VIEW_H_
...@@ -728,6 +728,7 @@ ...@@ -728,6 +728,7 @@
'browser/ui/cocoa/ui_localizer.mm', 'browser/ui/cocoa/ui_localizer.mm',
'browser/ui/cocoa/url_drop_target.h', 'browser/ui/cocoa/url_drop_target.h',
'browser/ui/cocoa/url_drop_target.mm', 'browser/ui/cocoa/url_drop_target.mm',
'browser/ui/cocoa/validation_message_bubble_cocoa.h',
'browser/ui/cocoa/validation_message_bubble_cocoa.mm', 'browser/ui/cocoa/validation_message_bubble_cocoa.mm',
'browser/ui/cocoa/validation_message_bubble_controller.h', 'browser/ui/cocoa/validation_message_bubble_controller.h',
'browser/ui/cocoa/vertical_gradient_view.h', 'browser/ui/cocoa/vertical_gradient_view.h',
...@@ -2284,6 +2285,7 @@ ...@@ -2284,6 +2285,7 @@
'browser/ui/views/validation_message_bubble_delegate.cc', 'browser/ui/views/validation_message_bubble_delegate.cc',
'browser/ui/views/validation_message_bubble_delegate.h', 'browser/ui/views/validation_message_bubble_delegate.h',
'browser/ui/views/validation_message_bubble_view.cc', 'browser/ui/views/validation_message_bubble_view.cc',
'browser/ui/views/validation_message_bubble_view.h',
'browser/ui/views/web_contents_modal_dialog_manager_views.cc', 'browser/ui/views/web_contents_modal_dialog_manager_views.cc',
'browser/ui/views/website_settings/permissions_bubble_view.cc', 'browser/ui/views/website_settings/permissions_bubble_view.cc',
'browser/ui/views/website_settings/permissions_bubble_view.h', 'browser/ui/views/website_settings/permissions_bubble_view.h',
......
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