| 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/ui/views/validation_message_bubble_delegate.h" | 7 #include "chrome/browser/ui/views/validation_message_bubble_delegate.h" |
| 8 #include "content/public/browser/render_widget_host.h" |
| 9 #include "content/public/browser/render_widget_host_view.h" |
| 8 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
| 9 | 11 |
| 10 namespace { | 12 namespace { |
| 11 | 13 |
| 12 // A ValidationMessageBubble implementation for Views. | 14 // A ValidationMessageBubble implementation for Views. |
| 13 class ValidationMessageBubbleImpl | 15 class ValidationMessageBubbleImpl |
| 14 : public chrome::ValidationMessageBubble, | 16 : public chrome::ValidationMessageBubble, |
| 15 public ValidationMessageBubbleDelegate::Observer { | 17 public ValidationMessageBubbleDelegate::Observer { |
| 16 public: | 18 public: |
| 17 ValidationMessageBubbleImpl(const gfx::Rect& anchor_in_screen, | 19 ValidationMessageBubbleImpl(const gfx::Rect& anchor_in_screen, |
| 18 const string16& main_text, | 20 const string16& main_text, |
| 19 const string16& sub_text); | 21 const string16& sub_text); |
| 20 | 22 |
| 21 virtual ~ValidationMessageBubbleImpl() { | 23 virtual ~ValidationMessageBubbleImpl() { |
| 22 if (delegate_ != NULL) | 24 if (delegate_ != NULL) |
| 23 delegate_->Hide(); | 25 delegate_->Close(); |
| 26 } |
| 27 |
| 28 virtual void MoveOnAnchor(content::RenderWidgetHost* widget_host, |
| 29 const gfx::Rect& anchor_in_root_view) OVERRIDE { |
| 30 if (!delegate_) |
| 31 return; |
| 32 delegate_->MoveOnAnchor(anchor_in_root_view |
| 33 + widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin()); |
| 24 } | 34 } |
| 25 | 35 |
| 26 // ValidationMessageBubbleDelegate::Observer override: | 36 // ValidationMessageBubbleDelegate::Observer override: |
| 27 virtual void WindowClosing() OVERRIDE { | 37 virtual void WindowClosing() OVERRIDE { |
| 28 delegate_ = NULL; | 38 delegate_ = NULL; |
| 29 } | 39 } |
| 30 | 40 |
| 31 private: | 41 private: |
| 32 ValidationMessageBubbleDelegate* delegate_; | 42 ValidationMessageBubbleDelegate* delegate_; |
| 33 | 43 |
| 34 DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleImpl); | 44 DISALLOW_COPY_AND_ASSIGN(ValidationMessageBubbleImpl); |
| 35 }; | 45 }; |
| 36 | 46 |
| 37 ValidationMessageBubbleImpl::ValidationMessageBubbleImpl( | 47 ValidationMessageBubbleImpl::ValidationMessageBubbleImpl( |
| 38 const gfx::Rect& anchor_in_screen, | 48 const gfx::Rect& anchor_in_screen, |
| 39 const string16& main_text, | 49 const string16& main_text, |
| 40 const string16& sub_text) { | 50 const string16& sub_text) { |
| 41 delegate_ = new ValidationMessageBubbleDelegate( | 51 delegate_ = new ValidationMessageBubbleDelegate( |
| 42 anchor_in_screen, main_text, sub_text, this); | 52 anchor_in_screen, main_text, sub_text, this); |
| 43 views::BubbleDelegateView::CreateBubble(delegate_); | 53 views::BubbleDelegateView::CreateBubble(delegate_); |
| 44 delegate_->GetWidget()->ShowInactive(); | 54 delegate_->GetWidget()->ShowInactive(); |
| 45 } | 55 } |
| 46 | 56 |
| 47 } // namespace | 57 } // namespace |
| 48 | 58 |
| 49 namespace chrome { | 59 namespace chrome { |
| 50 | 60 |
| 51 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( | 61 scoped_ptr<ValidationMessageBubble> ValidationMessageBubble::CreateAndShow( |
| 52 content::RenderWidgetHost*, | 62 content::RenderWidgetHost* widget_host, |
| 53 const gfx::Rect& anchor_in_screen, | 63 const gfx::Rect& anchor_in_root_view, |
| 54 const string16& main_text, | 64 const string16& main_text, |
| 55 const string16& sub_text) { | 65 const string16& sub_text) { |
| 66 const gfx::Rect& anchor_in_screen = anchor_in_root_view |
| 67 + widget_host->GetView()->GetViewBounds().origin().OffsetFromOrigin(); |
| 56 scoped_ptr<ValidationMessageBubble> bubble( | 68 scoped_ptr<ValidationMessageBubble> bubble( |
| 57 new ValidationMessageBubbleImpl(anchor_in_screen, main_text, sub_text)); | 69 new ValidationMessageBubbleImpl(anchor_in_screen, main_text, sub_text)); |
| 58 return bubble.Pass(); | 70 return bubble.Pass(); |
| 59 } | 71 } |
| 60 | 72 |
| 61 } // namespace chrome | 73 } // namespace chrome |
| OLD | NEW |