Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: chrome/browser/ui/views/validation_message_bubble_view.cc

Issue 2585263005: Merge "Fix form validation bubble positioning at hidpi." to M56 (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/validation_message_bubble_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ui/display/display.h"
12 #include "ui/display/screen.h"
12 #include "ui/views/controls/image_view.h" 13 #include "ui/views/controls/image_view.h"
13 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
14 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
15 16
16 namespace { 17 namespace {
17 18
18 const int kWindowMinWidth = 64; 19 const int kWindowMinWidth = 64;
19 const int kWindowMaxWidth = 256; 20 const int kWindowMaxWidth = 256;
20 const int kIconTextMargin = 8; 21 const int kIconTextMargin = 8;
21 const int kTextVerticalMargin = 4; 22 const int kTextVerticalMargin = 4;
22 23
23 } // namespace 24 } // namespace
24 25
25 ValidationMessageBubbleView::ValidationMessageBubbleView( 26 ValidationMessageBubbleView::ValidationMessageBubbleView(
26 content::WebContents* web_contents, 27 content::WebContents* web_contents,
27 const gfx::Rect& anchor_in_root_view, 28 const gfx::Rect& anchor_in_root_view,
28 const base::string16& main_text, 29 const base::string16& main_text,
29 const base::string16& sub_text) { 30 const base::string16& sub_text) {
30 content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); 31 content::RenderWidgetHostView* render_widget_host_view =
31 set_parent_window(rwhv->GetNativeView()); 32 web_contents->GetRenderWidgetHostView();
33 set_parent_window(render_widget_host_view->GetNativeView());
32 34
33 set_can_activate(false); 35 set_can_activate(false);
34 set_arrow(views::BubbleBorder::TOP_LEFT); 36 set_arrow(views::BubbleBorder::TOP_LEFT);
35 const gfx::Rect anchor_in_screen = 37 SetAnchorRect(
36 anchor_in_root_view + rwhv->GetViewBounds().origin().OffsetFromOrigin(); 38 RootViewToScreenRect(anchor_in_root_view, render_widget_host_view));
37 SetAnchorRect(anchor_in_screen);
38 39
39 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 40 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
40 views::ImageView* icon = new views::ImageView(); 41 views::ImageView* icon = new views::ImageView();
41 icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT)); 42 icon->SetImage(*bundle.GetImageSkiaNamed(IDR_INPUT_ALERT));
42 icon->SizeToPreferredSize(); 43 icon->SizeToPreferredSize();
43 AddChildView(icon); 44 AddChildView(icon);
44 45
45 views::Label* label = new views::Label( 46 views::Label* label = new views::Label(
46 main_text, bundle.GetFontList(ui::ResourceBundle::MediumFont)); 47 main_text, bundle.GetFontList(ui::ResourceBundle::MediumFont));
47 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 48 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
(...skipping 27 matching lines...) Expand all
75 } 76 }
76 77
77 size_ = gfx::Size(text_start_x + label_width, content_bottom); 78 size_ = gfx::Size(text_start_x + label_width, content_bottom);
78 79
79 views::BubbleDialogDelegateView::CreateBubble(this)->ShowInactive(); 80 views::BubbleDialogDelegateView::CreateBubble(this)->ShowInactive();
80 } 81 }
81 82
82 ValidationMessageBubbleView::~ValidationMessageBubbleView() { 83 ValidationMessageBubbleView::~ValidationMessageBubbleView() {
83 } 84 }
84 85
86 gfx::Rect ValidationMessageBubbleView::RootViewToScreenRect(
87 const gfx::Rect& rect_in_root_view,
88 const content::RenderWidgetHostView* render_widget_host_view) const {
89 gfx::NativeView view = render_widget_host_view->GetNativeView();
90 display::Display display =
91 display::Screen::GetScreen()->GetDisplayNearestWindow(view);
92 const float scale = display.device_scale_factor();
93 return gfx::ScaleToEnclosingRect(rect_in_root_view, 1 / scale) +
94 render_widget_host_view->GetViewBounds().origin().OffsetFromOrigin();
95 }
96
85 gfx::Size ValidationMessageBubbleView::GetPreferredSize() const { 97 gfx::Size ValidationMessageBubbleView::GetPreferredSize() const {
86 return size_; 98 return size_;
87 } 99 }
88 100
89 int ValidationMessageBubbleView::GetDialogButtons() const { 101 int ValidationMessageBubbleView::GetDialogButtons() const {
90 return ui::DIALOG_BUTTON_NONE; 102 return ui::DIALOG_BUTTON_NONE;
91 } 103 }
92 104
93 void ValidationMessageBubbleView::SetPositionRelativeToAnchor( 105 void ValidationMessageBubbleView::SetPositionRelativeToAnchor(
94 content::RenderWidgetHost* widget_host, 106 content::RenderWidgetHost* widget_host,
95 const gfx::Rect& anchor_in_root_view) { 107 const gfx::Rect& anchor_in_root_view) {
96 SetAnchorRect(anchor_in_root_view + 108 SetAnchorRect(
97 widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin()); 109 RootViewToScreenRect(anchor_in_root_view, widget_host->GetView()));
98 } 110 }
99 111
100 void ValidationMessageBubbleView::CloseValidationMessage() { 112 void ValidationMessageBubbleView::CloseValidationMessage() {
101 GetWidget()->Close(); 113 GetWidget()->Close();
102 } 114 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/validation_message_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698