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/validation_message_bubble.h" | 5 #include "chrome/browser/ui/validation_message_bubble.h" |
6 | 6 |
7 #include "chrome/browser/platform_util.h" | 7 #include "chrome/browser/platform_util.h" |
8 #include "chrome/browser/ui/views/validation_message_bubble_delegate.h" | 8 #include "chrome/browser/ui/views/validation_message_bubble_delegate.h" |
9 #include "content/public/browser/render_widget_host.h" | 9 #include "content/public/browser/render_widget_host.h" |
10 #include "content/public/browser/render_widget_host_view.h" | 10 #include "content/public/browser/render_widget_host_view.h" |
11 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // A ValidationMessageBubble implementation for Views. | 15 // A ValidationMessageBubble implementation for Views. |
16 class ValidationMessageBubbleImpl | 16 class ValidationMessageBubbleImpl |
17 : public chrome::ValidationMessageBubble, | 17 : public chrome::ValidationMessageBubble, |
18 public ValidationMessageBubbleDelegate::Observer { | 18 public ValidationMessageBubbleDelegate::Observer { |
19 public: | 19 public: |
20 ValidationMessageBubbleImpl(content::RenderWidgetHost* widget_host, | 20 ValidationMessageBubbleImpl(content::RenderWidgetHost* widget_host, |
21 const gfx::Rect& anchor_in_screen, | 21 const gfx::Rect& anchor_in_screen, |
22 const base::string16& main_text, | 22 const base::string16& main_text, |
23 const base::string16& sub_text); | 23 const base::string16& sub_text); |
24 | 24 |
25 virtual ~ValidationMessageBubbleImpl() { | 25 ~ValidationMessageBubbleImpl() override { |
26 if (delegate_ != NULL) | 26 if (delegate_ != NULL) |
27 delegate_->Close(); | 27 delegate_->Close(); |
28 } | 28 } |
29 | 29 |
30 virtual void SetPositionRelativeToAnchor( | 30 void SetPositionRelativeToAnchor( |
31 content::RenderWidgetHost* widget_host, | 31 content::RenderWidgetHost* widget_host, |
32 const gfx::Rect& anchor_in_root_view) override { | 32 const gfx::Rect& anchor_in_root_view) override { |
33 if (!delegate_) | 33 if (!delegate_) |
34 return; | 34 return; |
35 delegate_->SetPositionRelativeToAnchor(anchor_in_root_view + | 35 delegate_->SetPositionRelativeToAnchor(anchor_in_root_view + |
36 widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin()); | 36 widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin()); |
37 } | 37 } |
38 | 38 |
39 // ValidationMessageBubbleDelegate::Observer override: | 39 // ValidationMessageBubbleDelegate::Observer override: |
40 virtual void WindowClosing() override { | 40 void WindowClosing() override { delegate_ = NULL; } |
41 delegate_ = NULL; | |
42 } | |
43 | 41 |
44 private: | 42 private: |
45 ValidationMessageBubbleDelegate* delegate_; | 43 ValidationMessageBubbleDelegate* delegate_; |
46 | 44 |
47 DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleImpl); | 45 DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleImpl); |
48 }; | 46 }; |
49 | 47 |
50 ValidationMessageBubbleImpl::ValidationMessageBubbleImpl( | 48 ValidationMessageBubbleImpl::ValidationMessageBubbleImpl( |
51 content::RenderWidgetHost* widget_host, | 49 content::RenderWidgetHost* widget_host, |
52 const gfx::Rect& anchor_in_screen, | 50 const gfx::Rect& anchor_in_screen, |
(...skipping 17 matching lines...) Expand all Loading... |
70 const base::string16& main_text, | 68 const base::string16& main_text, |
71 const base::string16& sub_text) { | 69 const base::string16& sub_text) { |
72 const gfx::Rect anchor_in_screen = anchor_in_root_view | 70 const gfx::Rect anchor_in_screen = anchor_in_root_view |
73 + widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin(); | 71 + widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin(); |
74 scoped_ptr<ValidationMessageBubble> bubble(new ValidationMessageBubbleImpl( | 72 scoped_ptr<ValidationMessageBubble> bubble(new ValidationMessageBubbleImpl( |
75 widget_host, anchor_in_screen, main_text, sub_text)); | 73 widget_host, anchor_in_screen, main_text, sub_text)); |
76 return bubble.Pass(); | 74 return bubble.Pass(); |
77 } | 75 } |
78 | 76 |
79 } // namespace chrome | 77 } // namespace chrome |
OLD | NEW |