| OLD | NEW |
| 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" | 5 #include "chrome/browser/ui/cocoa/validation_message_bubble_cocoa.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 10 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 11 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 11 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 12 #import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h" | 12 #import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h" |
| 13 #include "chrome/browser/ui/validation_message_bubble.h" | 13 #include "chrome/browser/ui/validation_message_bubble.h" |
| 14 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/render_widget_host.h" | 15 #include "content/public/browser/render_widget_host.h" |
| 16 #include "content/public/browser/render_widget_host_view.h" | 16 #include "content/public/browser/render_widget_host_view.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 19 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 19 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 20 #import "ui/base/cocoa/base_view.h" | 20 #import "ui/base/cocoa/base_view.h" |
| 21 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 21 #import "ui/base/cocoa/flipped_view.h" | 22 #import "ui/base/cocoa/flipped_view.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 23 | 24 |
| 24 const CGFloat kWindowInitialWidth = 200; | 25 const CGFloat kWindowInitialWidth = 200; |
| 25 const CGFloat kWindowInitialHeight = 100; | 26 const CGFloat kWindowInitialHeight = 100; |
| 26 const CGFloat kWindowMinWidth = 64; | 27 const CGFloat kWindowMinWidth = 64; |
| 27 const CGFloat kWindowMaxWidth = 256; | 28 const CGFloat kWindowMaxWidth = 256; |
| 28 const CGFloat kWindowPadding = 8; | 29 const CGFloat kWindowPadding = 8; |
| 29 const CGFloat kIconTextMargin = 4; | 30 const CGFloat kIconTextMargin = 4; |
| 30 const CGFloat kTextVerticalMargin = 4; | 31 const CGFloat kTextVerticalMargin = 4; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // Converts |anchor_in_root_view| in rwhv coordinates to cocoa screen | 142 // Converts |anchor_in_root_view| in rwhv coordinates to cocoa screen |
| 142 // coordinates, and returns an NSPoint at the center of the bottom side of the | 143 // coordinates, and returns an NSPoint at the center of the bottom side of the |
| 143 // converted rectangle. | 144 // converted rectangle. |
| 144 NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host, | 145 NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host, |
| 145 const gfx::Rect& anchor_in_root_view) { | 146 const gfx::Rect& anchor_in_root_view) { |
| 146 BaseView* view = base::mac::ObjCCastStrict<BaseView>( | 147 BaseView* view = base::mac::ObjCCastStrict<BaseView>( |
| 147 widget_host->GetView()->GetNativeView()); | 148 widget_host->GetView()->GetNativeView()); |
| 148 NSRect cocoaRect = [view flipRectToNSRect:anchor_in_root_view]; | 149 NSRect cocoaRect = [view flipRectToNSRect:anchor_in_root_view]; |
| 149 NSRect windowRect = [view convertRect:cocoaRect toView:nil]; | 150 NSRect windowRect = [view convertRect:cocoaRect toView:nil]; |
| 150 NSPoint point = NSMakePoint(NSMidX(windowRect), NSMinY(windowRect)); | 151 NSPoint point = NSMakePoint(NSMidX(windowRect), NSMinY(windowRect)); |
| 151 return [[view window] convertBaseToScreen:point]; | 152 return ui::ConvertPointFromWindowToScreen([view window], point); |
| 152 } | 153 } |
| 153 | 154 |
| 154 ValidationMessageBubbleCocoa::ValidationMessageBubbleCocoa( | 155 ValidationMessageBubbleCocoa::ValidationMessageBubbleCocoa( |
| 155 content::WebContents* web_contents, | 156 content::WebContents* web_contents, |
| 156 const gfx::Rect& anchor_in_root_view, | 157 const gfx::Rect& anchor_in_root_view, |
| 157 const base::string16& main_text, | 158 const base::string16& main_text, |
| 158 const base::string16& sub_text) { | 159 const base::string16& sub_text) { |
| 159 content::RenderWidgetHost* widget_host = | 160 content::RenderWidgetHost* widget_host = |
| 160 web_contents->GetRenderViewHost()->GetWidget(); | 161 web_contents->GetRenderViewHost()->GetWidget(); |
| 161 controller_.reset([[[ValidationMessageBubbleController alloc] | 162 controller_.reset([[[ValidationMessageBubbleController alloc] |
| 162 init:[widget_host->GetView()->GetNativeView() window] | 163 init:[widget_host->GetView()->GetNativeView() window] |
| 163 anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view) | 164 anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view) |
| 164 mainText:main_text | 165 mainText:main_text |
| 165 subText:sub_text] retain]); | 166 subText:sub_text] retain]); |
| 166 } | 167 } |
| 167 | 168 |
| 168 ValidationMessageBubbleCocoa::~ValidationMessageBubbleCocoa() { | 169 ValidationMessageBubbleCocoa::~ValidationMessageBubbleCocoa() { |
| 169 [controller_ close]; | 170 [controller_ close]; |
| 170 } | 171 } |
| 171 | 172 |
| 172 void ValidationMessageBubbleCocoa::SetPositionRelativeToAnchor( | 173 void ValidationMessageBubbleCocoa::SetPositionRelativeToAnchor( |
| 173 content::RenderWidgetHost* widget_host, | 174 content::RenderWidgetHost* widget_host, |
| 174 const gfx::Rect& anchor_in_root_view) { | 175 const gfx::Rect& anchor_in_root_view) { |
| 175 [controller_ setAnchorPoint:GetAnchorPoint(widget_host, anchor_in_root_view)]; | 176 [controller_ setAnchorPoint:GetAnchorPoint(widget_host, anchor_in_root_view)]; |
| 176 } | 177 } |
| OLD | NEW |