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 "chrome/browser/ui/views/validation_message_bubble_view.h" | 5 #include "chrome/browser/ui/views/validation_message_bubble_view.h" |
| 6 | 6 |
| 7 #include "chrome/grit/theme_resources.h" | 7 #include "chrome/grit/theme_resources.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" | |
| 10 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/views/controls/image_view.h" | 11 #include "ui/views/controls/image_view.h" |
| 13 #include "ui/views/controls/label.h" | 12 #include "ui/views/controls/label.h" |
| 14 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 15 | 14 |
| 16 namespace { | 15 namespace { |
| 17 | 16 |
| 18 const int kWindowMinWidth = 64; | 17 const int kWindowMinWidth = 64; |
| 19 const int kWindowMaxWidth = 256; | 18 const int kWindowMaxWidth = 256; |
| 20 const int kIconTextMargin = 8; | 19 const int kIconTextMargin = 8; |
| 21 const int kTextVerticalMargin = 4; | 20 const int kTextVerticalMargin = 4; |
| 22 | 21 |
| 23 } // namespace | 22 } // namespace |
| 24 | 23 |
| 25 ValidationMessageBubbleView::ValidationMessageBubbleView( | 24 ValidationMessageBubbleView::ValidationMessageBubbleView( |
| 26 content::WebContents* web_contents, | 25 content::WebContents* web_contents, |
| 27 const gfx::Rect& anchor_in_root_view, | 26 const gfx::Rect& anchor_in_root_view, |
| 28 const base::string16& main_text, | 27 const base::string16& main_text, |
| 29 const base::string16& sub_text) { | 28 const base::string16& sub_text) { |
| 30 content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); | 29 content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); |
| 31 set_parent_window(rwhv->GetNativeView()); | 30 set_parent_window(rwhv->GetNativeView()); |
| 32 | 31 |
| 33 set_can_activate(false); | 32 set_can_activate(false); |
| 34 set_arrow(views::BubbleBorder::TOP_LEFT); | 33 set_arrow(views::BubbleBorder::TOP_LEFT); |
| 35 const gfx::Rect anchor_in_screen = | 34 SetAnchorRect(RootViewToScreenRect(anchor_in_root_view, rwhv)); |
| 36 anchor_in_root_view + rwhv->GetViewBounds().origin().OffsetFromOrigin(); | |
| 37 SetAnchorRect(anchor_in_screen); | |
| 38 | 35 |
| 39 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 36 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 40 views::ImageView* icon = new views::ImageView(); | 37 views::ImageView* icon = new views::ImageView(); |
| 41 icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT)); | 38 icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT)); |
| 42 icon->SizeToPreferredSize(); | 39 icon->SizeToPreferredSize(); |
| 43 AddChildView(icon); | 40 AddChildView(icon); |
| 44 | 41 |
| 45 views::Label* label = new views::Label( | 42 views::Label* label = new views::Label( |
| 46 main_text, bundle.GetFontList(ui::ResourceBundle::MediumFont)); | 43 main_text, bundle.GetFontList(ui::ResourceBundle::MediumFont)); |
| 47 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 44 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 75 } | 72 } |
| 76 | 73 |
| 77 size_ = gfx::Size(text_start_x + label_width, content_bottom); | 74 size_ = gfx::Size(text_start_x + label_width, content_bottom); |
| 78 | 75 |
| 79 views::BubbleDialogDelegateView::CreateBubble(this)->ShowInactive(); | 76 views::BubbleDialogDelegateView::CreateBubble(this)->ShowInactive(); |
| 80 } | 77 } |
| 81 | 78 |
| 82 ValidationMessageBubbleView::~ValidationMessageBubbleView() { | 79 ValidationMessageBubbleView::~ValidationMessageBubbleView() { |
| 83 } | 80 } |
| 84 | 81 |
| 82 gfx::Rect ValidationMessageBubbleView::RootViewToScreenRect( | |
| 83 const gfx::Rect& rect_in_root_view, | |
| 84 const content::RenderWidgetHostView* rwhv) const { | |
| 85 const float scale = rwhv->GetDeviceScaleFactor(); | |
| 86 return gfx::ScaleToEnclosingRect(rect_in_root_view, 1 / scale) + | |
|
msw
2016/11/10 18:59:14
Is there any chance this is zero? Consider adding
Bret
2016/11/11 23:51:27
I don't think we could reach this method if scale
| |
| 87 rwhv->GetViewBounds().origin().OffsetFromOrigin(); | |
|
sadrul
2016/11/10 20:44:41
Can you use aura::client::ScreenPositionClient ins
Bret
2016/11/11 23:51:27
I can't get access to aura-specific methods on Ren
sadrul
2016/11/12 02:30:44
You have the RenderWidgetHostView here. You can ge
Bret
2016/11/12 22:04:36
Okay that plumbing does work. But as far as I can
| |
| 88 } | |
| 89 | |
| 85 gfx::Size ValidationMessageBubbleView::GetPreferredSize() const { | 90 gfx::Size ValidationMessageBubbleView::GetPreferredSize() const { |
| 86 return size_; | 91 return size_; |
| 87 } | 92 } |
| 88 | 93 |
| 89 int ValidationMessageBubbleView::GetDialogButtons() const { | 94 int ValidationMessageBubbleView::GetDialogButtons() const { |
| 90 return ui::DIALOG_BUTTON_NONE; | 95 return ui::DIALOG_BUTTON_NONE; |
| 91 } | 96 } |
| 92 | 97 |
| 93 void ValidationMessageBubbleView::SetPositionRelativeToAnchor( | 98 void ValidationMessageBubbleView::SetPositionRelativeToAnchor( |
| 94 content::RenderWidgetHost* widget_host, | 99 content::RenderWidgetHost* widget_host, |
| 95 const gfx::Rect& anchor_in_root_view) { | 100 const gfx::Rect& anchor_in_root_view) { |
| 96 SetAnchorRect(anchor_in_root_view + | 101 SetAnchorRect( |
| 97 widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin()); | 102 RootViewToScreenRect(anchor_in_root_view, widget_host->GetView())); |
| 98 } | 103 } |
| 99 | 104 |
| 100 void ValidationMessageBubbleView::CloseValidationMessage() { | 105 void ValidationMessageBubbleView::CloseValidationMessage() { |
| 101 GetWidget()->Close(); | 106 GetWidget()->Close(); |
| 102 } | 107 } |
| OLD | NEW |