| 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 "base/mac/mac_util.h" |
| 5 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 7 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 8 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 8 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 9 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 9 #import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h" | 10 #import "chrome/browser/ui/cocoa/validation_message_bubble_controller.h" |
| 10 #include "chrome/browser/ui/validation_message_bubble.h" | 11 #include "chrome/browser/ui/validation_message_bubble.h" |
| 11 #include "content/public/browser/render_widget_host.h" | 12 #include "content/public/browser/render_widget_host.h" |
| 12 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
| 13 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
| 14 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 15 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 16 #import "ui/base/cocoa/base_view.h" |
| 15 #import "ui/base/cocoa/flipped_view.h" | 17 #import "ui/base/cocoa/flipped_view.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 17 | 19 |
| 18 const CGFloat kWindowInitialWidth = 200; | 20 const CGFloat kWindowInitialWidth = 200; |
| 19 const CGFloat kWindowInitialHeight = 100; | 21 const CGFloat kWindowInitialHeight = 100; |
| 20 const CGFloat kWindowMinWidth = 64; | 22 const CGFloat kWindowMinWidth = 64; |
| 21 const CGFloat kWindowMaxWidth = 256; | 23 const CGFloat kWindowMaxWidth = 256; |
| 22 const CGFloat kWindowPadding = 8; | 24 const CGFloat kWindowPadding = 8; |
| 23 const CGFloat kIconTextMargin = 4; | 25 const CGFloat kIconTextMargin = 4; |
| 24 const CGFloat kTextVerticalMargin = 4; | 26 const CGFloat kTextVerticalMargin = 4; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 return contentView; | 129 return contentView; |
| 128 } | 130 } |
| 129 | 131 |
| 130 | 132 |
| 131 @end // implementation ValidationMessageBubbleCocoa | 133 @end // implementation ValidationMessageBubbleCocoa |
| 132 | 134 |
| 133 // ---------------------------------------------------------------- | 135 // ---------------------------------------------------------------- |
| 134 | 136 |
| 135 namespace { | 137 namespace { |
| 136 | 138 |
| 139 // 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 // converted rectangle. |
| 142 NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host, |
| 143 const gfx::Rect& anchor_in_root_view) { |
| 144 BaseView* view = base::mac::ObjCCastStrict<BaseView>( |
| 145 widget_host->GetView()->GetNativeView()); |
| 146 NSRect cocoaRect = [view flipRectToNSRect:anchor_in_root_view]; |
| 147 NSRect windowRect = [view convertRect:cocoaRect toView:nil]; |
| 148 NSPoint point = NSMakePoint(NSMidX(windowRect), NSMinY(windowRect)); |
| 149 return [[view window] convertBaseToScreen:point]; |
| 150 } |
| 151 |
| 137 class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble { | 152 class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble { |
| 138 public: | 153 public: |
| 139 ValidationMessageBubbleCocoa(content::RenderWidgetHost* widget_host, | 154 ValidationMessageBubbleCocoa(content::RenderWidgetHost* widget_host, |
| 140 const gfx::Rect& anchor_in_screen, | 155 const gfx::Rect& anchor_in_root_view, |
| 141 const string16& main_text, | 156 const string16& main_text, |
| 142 const string16& sub_text) { | 157 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] | 158 controller_.reset([[[ValidationMessageBubbleController alloc] |
| 149 init:parent_window | 159 init:[widget_host->GetView()->GetNativeView() window] |
| 150 anchoredAt:anchor_point | 160 anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view) |
| 151 mainText:main_text | 161 mainText:main_text |
| 152 subText:sub_text] retain]); | 162 subText:sub_text] retain]); |
| 153 } | 163 } |
| 154 | 164 |
| 155 virtual ~ValidationMessageBubbleCocoa() { | 165 virtual ~ValidationMessageBubbleCocoa() { |
| 156 [controller_.get() close]; | 166 [controller_.get() close]; |
| 157 } | 167 } |
| 158 | 168 |
| 169 virtual void SetPositionRelativeToAnchor( |
| 170 content::RenderWidgetHost* widget_host, |
| 171 const gfx::Rect& anchor_in_root_view) OVERRIDE { |
| 172 [controller_.get() |
| 173 setAnchorPoint:GetAnchorPoint(widget_host, anchor_in_root_view)]; |
| 174 } |
| 175 |
| 159 private: | 176 private: |
| 160 scoped_nsobject<ValidationMessageBubbleController> controller_; | 177 scoped_nsobject<ValidationMessageBubbleController> controller_; |
| 161 }; | 178 }; |
| 162 | 179 |
| 163 } | 180 } |
| 164 | 181 |
| 165 // ---------------------------------------------------------------- | 182 // ---------------------------------------------------------------- |
| 166 | 183 |
| 167 namespace chrome { | 184 namespace chrome { |
| 168 | 185 |
| 169 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( | 186 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( |
| 170 content::RenderWidgetHost* widget_host, | 187 content::RenderWidgetHost* widget_host, |
| 171 const gfx::Rect& anchor_in_screen, | 188 const gfx::Rect& anchor_in_root_view, |
| 172 const string16& main_text, | 189 const string16& main_text, |
| 173 const string16& sub_text) { | 190 const string16& sub_text) { |
| 174 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleCocoa( | 191 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleCocoa( |
| 175 widget_host, anchor_in_screen, main_text, sub_text)).Pass(); | 192 widget_host, anchor_in_root_view, main_text, sub_text)).Pass(); |
| 176 } | 193 } |
| 177 | 194 |
| 178 } | 195 } |
| OLD | NEW |