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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/strings/sys_string_conversions.h" 6 #include "base/strings/sys_string_conversions.h"
7 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 7 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
8 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 8 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
9 #import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h" 9 #import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h"
10 #include "chrome/browser/ui/validation_message_bubble.h" 10 #include "chrome/browser/ui/validation_message_bubble.h"
11 #include "content/public/browser/render_widget_host.h" 11 #include "content/public/browser/render_widget_host.h"
12 #include "content/public/browser/render_widget_host_view.h" 12 #include "content/public/browser/render_widget_host_view.h"
13 #include "grit/theme_resources.h" 13 #include "grit/theme_resources.h"
14 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 14 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
15 #import "ui/base/cocoa/base_view.h"
15 #import "ui/base/cocoa/flipped_view.h" 16 #import "ui/base/cocoa/flipped_view.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 18
18 const CGFloat kWindowInitialWidth = 200; 19 const CGFloat kWindowInitialWidth = 200;
19 const CGFloat kWindowInitialHeight = 100; 20 const CGFloat kWindowInitialHeight = 100;
20 const CGFloat kWindowMinWidth = 64; 21 const CGFloat kWindowMinWidth = 64;
21 const CGFloat kWindowMaxWidth = 256; 22 const CGFloat kWindowMaxWidth = 256;
22 const CGFloat kWindowPadding = 8; 23 const CGFloat kWindowPadding = 8;
23 const CGFloat kIconTextMargin = 4; 24 const CGFloat kIconTextMargin = 4;
24 const CGFloat kTextVerticalMargin = 4; 25 const CGFloat kTextVerticalMargin = 4;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 return contentView; 128 return contentView;
128 } 129 }
129 130
130 131
131 @end // implementation ValidationMessageBubbleCocoa 132 @end // implementation ValidationMessageBubbleCocoa
132 133
133 // ---------------------------------------------------------------- 134 // ----------------------------------------------------------------
134 135
135 namespace { 136 namespace {
136 137
138 // Converts |anchor_in_root_view| in rwhv coordinates to cocoa screen
139 // coordinates, and returns an NSPoint at the center of the bottom side of the
140 // converted rectangle.
141 NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host,
142 const gfx::Rect& anchor_in_root_view) {
143 BaseView* view =
144 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.
145 NSRect cocoaRect = [view flipRectToNSRect:anchor_in_root_view];
146 NSRect windowRect = [view convertRect:cocoaRect toView:nil];
147 NSPoint point = NSMakePoint(NSMidX(windowRect), NSMinY(windowRect));
148 return [[view window] convertBaseToScreen:point];
149 }
150
137 class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble { 151 class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble {
138 public: 152 public:
139 ValidationMessageBubbleCocoa(content::RenderWidgetHost* widget_host, 153 ValidationMessageBubbleCocoa(content::RenderWidgetHost* widget_host,
140 const gfx::Rect& anchor_in_screen, 154 const gfx::Rect& anchor_in_root_view,
141 const string16& main_text, 155 const string16& main_text,
142 const string16& sub_text) { 156 const string16& sub_text) {
143 NSWindow* parent_window = [widget_host->GetView()->GetNativeView() window];
144 NSPoint anchor_point = NSMakePoint(
145 anchor_in_screen.x() + anchor_in_screen.width() / 2,
146 NSHeight([[parent_window screen] frame])
147 - (anchor_in_screen.y() + anchor_in_screen.height()));
148 controller_.reset([[[ValidationMessageBubbleController alloc] 157 controller_.reset([[[ValidationMessageBubbleController alloc]
149 init:parent_window 158 init:[widget_host->GetView()->GetNativeView() window]
150 anchoredAt:anchor_point 159 anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view)
151 mainText:main_text 160 mainText:main_text
152 subText:sub_text] retain]); 161 subText:sub_text] retain]);
153 } 162 }
154 163
155 virtual ~ValidationMessageBubbleCocoa() { 164 virtual ~ValidationMessageBubbleCocoa() {
156 [controller_.get() close]; 165 [controller_.get() close];
157 } 166 }
158 167
168 virtual void SetPositionRelativeToAnchor(
169 content::RenderWidgetHost* widget_host,
170 const gfx::Rect& anchor_in_root_view) OVERRIDE {
171 [controller_.get()
172 setAnchorPoint:GetAnchorPoint(widget_host, anchor_in_root_view)];
173 }
174
159 private: 175 private:
160 scoped_nsobject<ValidationMessageBubbleController> controller_; 176 scoped_nsobject<ValidationMessageBubbleController> controller_;
161 }; 177 };
162 178
163 } 179 }
164 180
165 // ---------------------------------------------------------------- 181 // ----------------------------------------------------------------
166 182
167 namespace chrome { 183 namespace chrome {
168 184
169 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( 185 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow(
170 content::RenderWidgetHost* widget_host, 186 content::RenderWidgetHost* widget_host,
171 const gfx::Rect& anchor_in_screen, 187 const gfx::Rect& anchor_in_root_view,
172 const string16& main_text, 188 const string16& main_text,
173 const string16& sub_text) { 189 const string16& sub_text) {
174 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleCocoa( 190 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleCocoa(
175 widget_host, anchor_in_screen, main_text, sub_text)).Pass(); 191 widget_host, anchor_in_root_view, main_text, sub_text)).Pass();
176 } 192 }
177 193
178 } 194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698