| 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/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "ui/base/layout.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/display/display.h" | |
| 12 #include "ui/display/screen.h" | |
| 13 #include "ui/views/controls/image_view.h" | 12 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
| 15 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 const int kWindowMinWidth = 64; | 18 const int kWindowMinWidth = 64; |
| 20 const int kWindowMaxWidth = 256; | 19 const int kWindowMaxWidth = 256; |
| 21 const int kIconTextMargin = 8; | 20 const int kIconTextMargin = 8; |
| 22 const int kTextVerticalMargin = 4; | 21 const int kTextVerticalMargin = 4; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 views::BubbleDialogDelegateView::CreateBubble(this)->ShowInactive(); | 79 views::BubbleDialogDelegateView::CreateBubble(this)->ShowInactive(); |
| 81 } | 80 } |
| 82 | 81 |
| 83 ValidationMessageBubbleView::~ValidationMessageBubbleView() { | 82 ValidationMessageBubbleView::~ValidationMessageBubbleView() { |
| 84 } | 83 } |
| 85 | 84 |
| 86 gfx::Rect ValidationMessageBubbleView::RootViewToScreenRect( | 85 gfx::Rect ValidationMessageBubbleView::RootViewToScreenRect( |
| 87 const gfx::Rect& rect_in_root_view, | 86 const gfx::Rect& rect_in_root_view, |
| 88 const content::RenderWidgetHostView* render_widget_host_view) const { | 87 const content::RenderWidgetHostView* render_widget_host_view) const { |
| 89 gfx::NativeView view = render_widget_host_view->GetNativeView(); | 88 gfx::NativeView view = render_widget_host_view->GetNativeView(); |
| 90 display::Display display = | 89 const float scale = ui::GetScaleFactorForNativeView(view); |
| 91 display::Screen::GetScreen()->GetDisplayNearestWindow(view); | |
| 92 const float scale = display.device_scale_factor(); | |
| 93 return gfx::ScaleToEnclosingRect(rect_in_root_view, 1 / scale) + | 90 return gfx::ScaleToEnclosingRect(rect_in_root_view, 1 / scale) + |
| 94 render_widget_host_view->GetViewBounds().origin().OffsetFromOrigin(); | 91 render_widget_host_view->GetViewBounds().origin().OffsetFromOrigin(); |
| 95 } | 92 } |
| 96 | 93 |
| 97 gfx::Size ValidationMessageBubbleView::GetPreferredSize() const { | 94 gfx::Size ValidationMessageBubbleView::GetPreferredSize() const { |
| 98 return size_; | 95 return size_; |
| 99 } | 96 } |
| 100 | 97 |
| 101 int ValidationMessageBubbleView::GetDialogButtons() const { | 98 int ValidationMessageBubbleView::GetDialogButtons() const { |
| 102 return ui::DIALOG_BUTTON_NONE; | 99 return ui::DIALOG_BUTTON_NONE; |
| 103 } | 100 } |
| 104 | 101 |
| 105 void ValidationMessageBubbleView::SetPositionRelativeToAnchor( | 102 void ValidationMessageBubbleView::SetPositionRelativeToAnchor( |
| 106 content::RenderWidgetHost* widget_host, | 103 content::RenderWidgetHost* widget_host, |
| 107 const gfx::Rect& anchor_in_root_view) { | 104 const gfx::Rect& anchor_in_root_view) { |
| 108 SetAnchorRect( | 105 SetAnchorRect( |
| 109 RootViewToScreenRect(anchor_in_root_view, widget_host->GetView())); | 106 RootViewToScreenRect(anchor_in_root_view, widget_host->GetView())); |
| 110 } | 107 } |
| 111 | 108 |
| 112 void ValidationMessageBubbleView::CloseValidationMessage() { | 109 void ValidationMessageBubbleView::CloseValidationMessage() { |
| 113 GetWidget()->Close(); | 110 GetWidget()->Close(); |
| 114 } | 111 } |
| OLD | NEW |