OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/browser_bubble.h" | 5 #include "chrome/browser/views/browser_bubble.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "chrome/browser/views/frame/browser_view.h" | 8 #include "chrome/browser/views/frame/browser_view.h" |
9 #include "views/widget/root_view.h" | 9 #include "views/widget/root_view.h" |
10 #include "views/window/window.h" | 10 #include "views/window/window.h" |
11 | 11 |
| 12 namespace { |
| 13 |
| 14 BrowserView* GetBrowserViewFromFrame(views::Widget* frame) { |
| 15 BrowserView* browser_view = NULL; |
| 16 views::Window* window = frame->GetWindow(); |
| 17 if (window) { |
| 18 browser_view = BrowserView::GetBrowserViewForNativeWindow( |
| 19 window->GetNativeWindow()); |
| 20 DCHECK(browser_view); |
| 21 } |
| 22 return browser_view; |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
12 BrowserBubble::BrowserBubble(views::View* view, views::Widget* frame, | 27 BrowserBubble::BrowserBubble(views::View* view, views::Widget* frame, |
13 const gfx::Point& origin) | 28 const gfx::Point& origin) |
14 : frame_(frame), | 29 : frame_(frame), |
15 view_(view), | 30 view_(view), |
16 visible_(false), | 31 visible_(false), |
17 delegate_(NULL), | 32 delegate_(NULL), |
18 attached_(false) { | 33 attached_(false) { |
19 frame_native_view_ = frame_->GetNativeView(); | 34 frame_native_view_ = frame_->GetNativeView(); |
20 gfx::Size size = view->GetPreferredSize(); | 35 gfx::Size size = view->GetPreferredSize(); |
21 bounds_.SetRect(origin.x(), origin.y(), size.width(), size.height()); | 36 bounds_.SetRect(origin.x(), origin.y(), size.width(), size.height()); |
(...skipping 10 matching lines...) Expand all Loading... |
32 // is a descendant of BrowserView's destructor, which leads to problems. | 47 // is a descendant of BrowserView's destructor, which leads to problems. |
33 // In that case, Detach doesn't need to get called anyway since BrowserView | 48 // In that case, Detach doesn't need to get called anyway since BrowserView |
34 // will do the necessary cleanup. | 49 // will do the necessary cleanup. |
35 } | 50 } |
36 | 51 |
37 void BrowserBubble::DetachFromBrowser() { | 52 void BrowserBubble::DetachFromBrowser() { |
38 DCHECK(attached_); | 53 DCHECK(attached_); |
39 if (!attached_) | 54 if (!attached_) |
40 return; | 55 return; |
41 attached_ = false; | 56 attached_ = false; |
42 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow( | 57 |
43 frame_->GetWindow()->GetNativeWindow()); | 58 BrowserView* browser_view = GetBrowserViewFromFrame(frame_); |
44 if (browser_view) | 59 if (browser_view) |
45 browser_view->DetachBrowserBubble(this); | 60 browser_view->DetachBrowserBubble(this); |
46 } | 61 } |
47 | 62 |
48 void BrowserBubble::AttachToBrowser() { | 63 void BrowserBubble::AttachToBrowser() { |
49 DCHECK(!attached_); | 64 DCHECK(!attached_); |
50 if (attached_) | 65 if (attached_) |
51 return; | 66 return; |
52 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow( | 67 |
53 frame_->GetWindow()->GetNativeWindow()); | 68 BrowserView* browser_view = GetBrowserViewFromFrame(frame_); |
54 DCHECK(browser_view); | 69 if (browser_view) |
55 if (browser_view) { | |
56 browser_view->AttachBrowserBubble(this); | 70 browser_view->AttachBrowserBubble(this); |
57 attached_ = true; | 71 |
58 } | 72 attached_ = true; |
59 } | 73 } |
60 | 74 |
61 void BrowserBubble::BrowserWindowMoved() { | 75 void BrowserBubble::BrowserWindowMoved() { |
62 if (delegate_) | 76 if (delegate_) |
63 delegate_->BubbleBrowserWindowMoved(this); | 77 delegate_->BubbleBrowserWindowMoved(this); |
64 else | 78 else |
65 Hide(); | 79 Hide(); |
66 if (visible_) | 80 if (visible_) |
67 Reposition(); | 81 Reposition(); |
68 } | 82 } |
(...skipping 21 matching lines...) Expand all Loading... |
90 views::View::ConvertPointToScreen(frame_->GetRootView(), &top_left); | 104 views::View::ConvertPointToScreen(frame_->GetRootView(), &top_left); |
91 MovePopup(top_left.x() + bounds_.x(), | 105 MovePopup(top_left.x() + bounds_.x(), |
92 top_left.y() + bounds_.y(), | 106 top_left.y() + bounds_.y(), |
93 bounds_.width(), | 107 bounds_.width(), |
94 bounds_.height()); | 108 bounds_.height()); |
95 } | 109 } |
96 | 110 |
97 void BrowserBubble::ResizeToView() { | 111 void BrowserBubble::ResizeToView() { |
98 SetBounds(bounds_.x(), bounds_.y(), view_->width(), view_->height()); | 112 SetBounds(bounds_.x(), bounds_.y(), view_->width(), view_->height()); |
99 } | 113 } |
OLD | NEW |