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

Side by Side Diff: chrome/browser/ui/cocoa/validation_message_bubble_cocoa.mm

Issue 867323005: MacViews: Fix duplicate definition of ValidationMessageBubble::ShowAndCreate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@FirstResponder
Patch Set: Created 5 years, 11 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
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 "chrome/browser/ui/cocoa/validation_message_bubble_cocoa.h"
6
5 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
6 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
7 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
8 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 10 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
9 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 11 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
10 #import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h" 12 #import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h"
11 #include "chrome/browser/ui/validation_message_bubble.h" 13 #include "chrome/browser/ui/validation_message_bubble.h"
12 #include "content/public/browser/render_widget_host.h" 14 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/render_widget_host_view.h" 15 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h"
14 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
15 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" 18 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h"
16 #import "ui/base/cocoa/base_view.h" 19 #import "ui/base/cocoa/base_view.h"
17 #import "ui/base/cocoa/flipped_view.h" 20 #import "ui/base/cocoa/flipped_view.h"
18 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
19 22
20 const CGFloat kWindowInitialWidth = 200; 23 const CGFloat kWindowInitialWidth = 200;
21 const CGFloat kWindowInitialHeight = 100; 24 const CGFloat kWindowInitialHeight = 100;
22 const CGFloat kWindowMinWidth = 64; 25 const CGFloat kWindowMinWidth = 64;
23 const CGFloat kWindowMaxWidth = 256; 26 const CGFloat kWindowMaxWidth = 256;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 130
128 [contentView setFrame:contentFrame]; 131 [contentView setFrame:contentFrame];
129 return contentView; 132 return contentView;
130 } 133 }
131 134
132 135
133 @end // implementation ValidationMessageBubbleCocoa 136 @end // implementation ValidationMessageBubbleCocoa
134 137
135 // ---------------------------------------------------------------- 138 // ----------------------------------------------------------------
136 139
137 namespace {
138
139 // Converts |anchor_in_root_view| in rwhv coordinates to cocoa screen 140 // Converts |anchor_in_root_view| in rwhv coordinates to cocoa screen
140 // coordinates, and returns an NSPoint at the center of the bottom side of the 141 // coordinates, and returns an NSPoint at the center of the bottom side of the
141 // converted rectangle. 142 // converted rectangle.
142 NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host, 143 NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host,
143 const gfx::Rect& anchor_in_root_view) { 144 const gfx::Rect& anchor_in_root_view) {
144 BaseView* view = base::mac::ObjCCastStrict<BaseView>( 145 BaseView* view = base::mac::ObjCCastStrict<BaseView>(
145 widget_host->GetView()->GetNativeView()); 146 widget_host->GetView()->GetNativeView());
146 NSRect cocoaRect = [view flipRectToNSRect:anchor_in_root_view]; 147 NSRect cocoaRect = [view flipRectToNSRect:anchor_in_root_view];
147 NSRect windowRect = [view convertRect:cocoaRect toView:nil]; 148 NSRect windowRect = [view convertRect:cocoaRect toView:nil];
148 NSPoint point = NSMakePoint(NSMidX(windowRect), NSMinY(windowRect)); 149 NSPoint point = NSMakePoint(NSMidX(windowRect), NSMinY(windowRect));
149 return [[view window] convertBaseToScreen:point]; 150 return [[view window] convertBaseToScreen:point];
150 } 151 }
151 152
152 class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble { 153 ValidationMessageBubbleCocoa::ValidationMessageBubbleCocoa(
153 public: 154 content::WebContents* web_contents,
154 ValidationMessageBubbleCocoa(content::RenderWidgetHost* widget_host,
155 const gfx::Rect& anchor_in_root_view,
156 const base::string16& main_text,
157 const base::string16& sub_text) {
158 controller_.reset([[[ValidationMessageBubbleController alloc]
159 init:[widget_host->GetView()->GetNativeView() window]
160 anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view)
161 mainText:main_text
162 subText:sub_text] retain]);
163 }
164
165 ~ValidationMessageBubbleCocoa() override { [controller_.get() close]; }
166
167 void SetPositionRelativeToAnchor(
168 content::RenderWidgetHost* widget_host,
169 const gfx::Rect& anchor_in_root_view) override {
170 [controller_.get()
171 setAnchorPoint:GetAnchorPoint(widget_host, anchor_in_root_view)];
172 }
173
174 private:
175 base::scoped_nsobject<ValidationMessageBubbleController> controller_;
176 };
177
178 }
179
180 // ----------------------------------------------------------------
181
182 namespace chrome {
183
184 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow(
185 content::RenderWidgetHost* widget_host,
186 const gfx::Rect& anchor_in_root_view, 155 const gfx::Rect& anchor_in_root_view,
187 const base::string16& main_text, 156 const base::string16& main_text,
188 const base::string16& sub_text) { 157 const base::string16& sub_text) {
189 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleCocoa( 158 content::RenderWidgetHost* widget_host = web_contents->GetRenderViewHost();
190 widget_host, anchor_in_root_view, main_text, sub_text)).Pass(); 159 controller_.reset([[[ValidationMessageBubbleController alloc]
160 init:[widget_host->GetView()->GetNativeView() window]
161 anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view)
162 mainText:main_text
163 subText:sub_text] retain]);
191 } 164 }
192 165
166 ValidationMessageBubbleCocoa::~ValidationMessageBubbleCocoa() {
167 [controller_ close];
193 } 168 }
169
170 void ValidationMessageBubbleCocoa::SetPositionRelativeToAnchor(
171 content::RenderWidgetHost* widget_host,
172 const gfx::Rect& anchor_in_root_view) {
173 [controller_ setAnchorPoint:GetAnchorPoint(widget_host, anchor_in_root_view)];
174 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/validation_message_bubble_cocoa.h ('k') | chrome/browser/ui/tab_dialogs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698