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* render_widget_host_view = |
| 31 set_parent_window(rwhv->GetNativeView()); | 30 web_contents->GetRenderWidgetHostView(); |
| 31 set_parent_window(render_widget_host_view->GetNativeView()); | |
| 32 | 32 |
| 33 set_can_activate(false); | 33 set_can_activate(false); |
| 34 set_arrow(views::BubbleBorder::TOP_LEFT); | 34 set_arrow(views::BubbleBorder::TOP_LEFT); |
| 35 const gfx::Rect anchor_in_screen = | 35 SetAnchorRect( |
| 36 anchor_in_root_view + rwhv->GetViewBounds().origin().OffsetFromOrigin(); | 36 RootViewToScreenRect(anchor_in_root_view, render_widget_host_view)); |
| 37 SetAnchorRect(anchor_in_screen); | |
| 38 | 37 |
| 39 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 38 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 40 views::ImageView* icon = new views::ImageView(); | 39 views::ImageView* icon = new views::ImageView(); |
| 41 icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT)); | 40 icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT)); |
| 42 icon->SizeToPreferredSize(); | 41 icon->SizeToPreferredSize(); |
| 43 AddChildView(icon); | 42 AddChildView(icon); |
| 44 | 43 |
| 45 views::Label* label = new views::Label( | 44 views::Label* label = new views::Label( |
| 46 main_text, bundle.GetFontList(ui::ResourceBundle::MediumFont)); | 45 main_text, bundle.GetFontList(ui::ResourceBundle::MediumFont)); |
| 47 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 46 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 75 } | 74 } |
| 76 | 75 |
| 77 size_ = gfx::Size(text_start_x + label_width, content_bottom); | 76 size_ = gfx::Size(text_start_x + label_width, content_bottom); |
| 78 | 77 |
| 79 views::BubbleDialogDelegateView::CreateBubble(this)->ShowInactive(); | 78 views::BubbleDialogDelegateView::CreateBubble(this)->ShowInactive(); |
| 80 } | 79 } |
| 81 | 80 |
| 82 ValidationMessageBubbleView::~ValidationMessageBubbleView() { | 81 ValidationMessageBubbleView::~ValidationMessageBubbleView() { |
| 83 } | 82 } |
| 84 | 83 |
| 84 gfx::Rect ValidationMessageBubbleView::RootViewToScreenRect( | |
| 85 const gfx::Rect& rect_in_root_view, | |
| 86 const content::RenderWidgetHostView* render_widget_host_view) const { | |
| 87 const float scale = render_widget_host_view->GetDeviceScaleFactor(); | |
|
sadrul
2016/11/14 16:58:03
Note that if you really need this, you can also ge
| |
| 88 return gfx::ScaleToEnclosingRect(rect_in_root_view, 1 / scale) + | |
| 89 render_widget_host_view->GetViewBounds().origin().OffsetFromOrigin(); | |
| 90 } | |
| 91 | |
| 85 gfx::Size ValidationMessageBubbleView::GetPreferredSize() const { | 92 gfx::Size ValidationMessageBubbleView::GetPreferredSize() const { |
| 86 return size_; | 93 return size_; |
| 87 } | 94 } |
| 88 | 95 |
| 89 int ValidationMessageBubbleView::GetDialogButtons() const { | 96 int ValidationMessageBubbleView::GetDialogButtons() const { |
| 90 return ui::DIALOG_BUTTON_NONE; | 97 return ui::DIALOG_BUTTON_NONE; |
| 91 } | 98 } |
| 92 | 99 |
| 93 void ValidationMessageBubbleView::SetPositionRelativeToAnchor( | 100 void ValidationMessageBubbleView::SetPositionRelativeToAnchor( |
| 94 content::RenderWidgetHost* widget_host, | 101 content::RenderWidgetHost* widget_host, |
| 95 const gfx::Rect& anchor_in_root_view) { | 102 const gfx::Rect& anchor_in_root_view) { |
| 96 SetAnchorRect(anchor_in_root_view + | 103 SetAnchorRect( |
| 97 widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin()); | 104 RootViewToScreenRect(anchor_in_root_view, widget_host->GetView())); |
| 98 } | 105 } |
| 99 | 106 |
| 100 void ValidationMessageBubbleView::CloseValidationMessage() { | 107 void ValidationMessageBubbleView::CloseValidationMessage() { |
| 101 GetWidget()->Close(); | 108 GetWidget()->Close(); |
| 102 } | 109 } |
| OLD | NEW |