Chromium Code Reviews| 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/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 #include "chrome/browser/ui/validation_message_bubble.h" | 7 #include "chrome/browser/ui/validation_message_bubble.h" |
| 8 #include "content/public/browser/render_widget_host.h" | 8 #include "content/public/browser/render_widget_host.h" |
| 9 #include "content/public/browser/render_widget_host_view.h" | 9 #include "content/public/browser/render_widget_host_view.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 return contentView; | 127 return contentView; |
| 128 } | 128 } |
| 129 | 129 |
| 130 | 130 |
| 131 @end // implementation ValidationMessageBubbleCocoa | 131 @end // implementation ValidationMessageBubbleCocoa |
| 132 | 132 |
| 133 // ---------------------------------------------------------------- | 133 // ---------------------------------------------------------------- |
| 134 | 134 |
| 135 namespace { | 135 namespace { |
| 136 | 136 |
| 137 NSPoint GetAnchorPoint(content::RenderWidgetHost* widget_host, | |
|
Nico
2013/06/07 16:35:31
Can you add a comment above this function, explain
tkent
2013/06/10 06:15:37
Done.
| |
| 138 const gfx::Rect& anchor_in_root_view) { | |
| 139 content::RenderWidgetHostView* view = widget_host->GetView(); | |
| 140 gfx::Rect anchor_in_screen = anchor_in_root_view | |
| 141 + view->GetViewBounds().origin().OffsetFromOrigin(); | |
| 142 NSWindow* parent_window = [view->GetNativeView() window]; | |
| 143 return NSMakePoint(anchor_in_screen.x() + anchor_in_screen.width() / 2, | |
| 144 NSHeight([[parent_window screen] frame]) | |
| 145 - (anchor_in_screen.y() + anchor_in_screen.height())); | |
|
Nico
2013/06/07 16:35:31
If this function does what I think it does, the mo
tkent
2013/06/10 06:15:37
Done.
| |
| 146 } | |
| 147 | |
| 137 class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble { | 148 class ValidationMessageBubbleCocoa : public chrome::ValidationMessageBubble { |
| 138 public: | 149 public: |
| 139 ValidationMessageBubbleCocoa(content::RenderWidgetHost* widget_host, | 150 ValidationMessageBubbleCocoa(content::RenderWidgetHost* widget_host, |
| 140 const gfx::Rect& anchor_in_screen, | 151 const gfx::Rect& anchor_in_root_view, |
| 141 const string16& main_text, | 152 const string16& main_text, |
| 142 const string16& sub_text) { | 153 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] | 154 controller_.reset([[[ValidationMessageBubbleController alloc] |
| 149 init:parent_window | 155 init:[widget_host->GetView()->GetNativeView() window] |
| 150 anchoredAt:anchor_point | 156 anchoredAt:GetAnchorPoint(widget_host, anchor_in_root_view) |
| 151 mainText:main_text | 157 mainText:main_text |
| 152 subText:sub_text] retain]); | 158 subText:sub_text] retain]); |
| 153 } | 159 } |
| 154 | 160 |
| 155 virtual ~ValidationMessageBubbleCocoa() { | 161 virtual ~ValidationMessageBubbleCocoa() { |
| 156 [controller_.get() close]; | 162 [controller_.get() close]; |
| 157 } | 163 } |
| 158 | 164 |
| 165 virtual void MoveOnAnchor(content::RenderWidgetHost* widget_host, | |
|
Nico
2013/06/07 16:35:31
(same nit as in the android file here too, and in
tkent
2013/06/10 06:15:37
Done.
| |
| 166 const gfx::Rect& anchor_in_root_view) OVERRIDE { | |
| 167 [controller_.get() | |
| 168 setAnchorPoint:GetAnchorPoint(widget_host, anchor_in_root_view)]; | |
| 169 } | |
| 170 | |
| 159 private: | 171 private: |
| 160 scoped_nsobject<ValidationMessageBubbleController> controller_; | 172 scoped_nsobject<ValidationMessageBubbleController> controller_; |
| 161 }; | 173 }; |
| 162 | 174 |
| 163 } | 175 } |
| 164 | 176 |
| 165 // ---------------------------------------------------------------- | 177 // ---------------------------------------------------------------- |
| 166 | 178 |
| 167 namespace chrome { | 179 namespace chrome { |
| 168 | 180 |
| 169 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( | 181 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( |
| 170 content::RenderWidgetHost* widget_host, | 182 content::RenderWidgetHost* widget_host, |
| 171 const gfx::Rect& anchor_in_screen, | 183 const gfx::Rect& anchor_in_root_view, |
| 172 const string16& main_text, | 184 const string16& main_text, |
| 173 const string16& sub_text) { | 185 const string16& sub_text) { |
| 174 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleCocoa( | 186 return scoped_ptr<ValidationMessageBubble>(new ValidationMessageBubbleCocoa( |
| 175 widget_host, anchor_in_screen, main_text, sub_text)).Pass(); | 187 widget_host, anchor_in_root_view, main_text, sub_text)).Pass(); |
| 176 } | 188 } |
| 177 | 189 |
| 178 } | 190 } |
| OLD | NEW |