Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8176)

Unified Diff: chrome/browser/ui/cocoa/validation_message_bubble_cocoa.mm

Issue 16583005: Some improvement of validation message bubble UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: renaming Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/validation_message_bubble_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/validation_message_bubble_cocoa.mm b/chrome/browser/ui/cocoa/validation_message_bubble_cocoa.mm
index e6a7db5c7c0ba3e5d7bacc56cff5ee001a0ad020..6d889970e5c0066bf35af9acfc75accc58fab016 100644
--- a/chrome/browser/ui/cocoa/validation_message_bubble_cocoa.mm
+++ b/chrome/browser/ui/cocoa/validation_message_bubble_cocoa.mm
@@ -12,6 +12,7 @@
#include "content/public/browser/render_widget_host_view.h"
#include "grit/theme_resources.h"
#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
+#import "ui/base/cocoa/base_view.h"
#import "ui/base/cocoa/flipped_view.h"
#include "ui/base/resource/resource_bundle.h"
@@ -134,20 +135,28 @@ anchoredAt:(NSPoint)anchorPoint
namespace {
+// 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
+// converted rectangle.
+NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host,
+ const gfx::Rect& anchor_in_root_view) {
+ BaseView* view =
+ static_cast<BaseView*>(widget_host->GetView()->GetNativeView());
Nico 2013/06/10 14:51:40 consider base::mac::ObjCCastStrict<> instead of st
tkent 2013/06/11 07:02:43 Done.
+ NSRect cocoaRect = [view flipRectToNSRect:anchor_in_root_view];
+ NSRect windowRect = [view convertRect:cocoaRect toView:nil];
+ NSPoint point = NSMakePoint(NSMidX(windowRect), NSMinY(windowRect));
+ return [[view window] convertBaseToScreen:point];
+}
+
class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble {
public:
ValidationMessageBubbleCocoa(content::RenderWidgetHost* widget_host,
- const gfx::Rect& anchor_in_screen,
+ const gfx::Rect& anchor_in_root_view,
const string16& main_text,
const string16& sub_text) {
- NSWindow* parent_window = [widget_host->GetView()->GetNativeView() window];
- NSPoint anchor_point = NSMakePoint(
- anchor_in_screen.x() + anchor_in_screen.width() / 2,
- NSHeight([[parent_window screen] frame])
- - (anchor_in_screen.y() + anchor_in_screen.height()));
controller_.reset([[[ValidationMessageBubbleController alloc]
- init:parent_window
- anchoredAt:anchor_point
+ init:[widget_host->GetView()->GetNativeView() window]
+ anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view)
mainText:main_text
subText:sub_text] retain]);
}
@@ -156,6 +165,13 @@ class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble {
[controller_.get() close];
}
+ virtual 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:
scoped_nsobject<ValidationMessageBubbleController> controller_;
};
@@ -168,11 +184,11 @@ namespace chrome {
scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow(
content::RenderWidgetHost* widget_host,
- const gfx::Rect& anchor_in_screen,
+ const gfx::Rect& anchor_in_root_view,
const string16& main_text,
const string16& sub_text) {
return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleCocoa(
- widget_host, anchor_in_screen, main_text, sub_text)).Pass();
+ widget_host, anchor_in_root_view, main_text, sub_text)).Pass();
}
}

Powered by Google App Engine
This is Rietveld 408576698