| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_bubble.h" | 5 #include "chrome/browser/ui/views/browser_bubble.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/views/frame/browser_view.h" | 7 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
| 9 #include "chrome/browser/external_tab_container_win.h" | 9 #include "chrome/browser/external_tab_container_win.h" |
| 10 #endif | 10 #endif |
| 11 #include "views/widget/root_view.h" | 11 #include "views/widget/root_view.h" |
| 12 #include "views/window/window.h" | 12 #include "views/window/window.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 BrowserBubbleHost* GetBubbleHostFromFrame(views::Widget* frame) { | 16 BrowserBubbleHost* GetBubbleHostFromFrame(views::Widget* frame) { |
| 17 if (!frame) | 17 if (!frame) |
| 18 return NULL; | 18 return NULL; |
| 19 | 19 |
| 20 BrowserBubbleHost* bubble_host = NULL; | 20 BrowserBubbleHost* bubble_host = NULL; |
| 21 views::Window* window = frame->GetWindow(); | 21 views::Window* window = frame->GetContainingWindow(); |
| 22 if (window) { | 22 if (window) { |
| 23 bubble_host = BrowserView::GetBrowserViewForNativeWindow( | 23 bubble_host = BrowserView::GetBrowserViewForNativeWindow( |
| 24 window->GetNativeWindow()); | 24 window->GetNativeWindow()); |
| 25 DCHECK(bubble_host); | 25 DCHECK(bubble_host); |
| 26 } | 26 } |
| 27 | 27 |
| 28 return bubble_host; | 28 return bubble_host; |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 BrowserBubble::BrowserBubble(views::View* view, | 33 BrowserBubble::BrowserBubble(views::View* view, |
| 34 views::Widget* frame, | 34 views::Widget* frame, |
| 35 const gfx::Rect& relative_to, | 35 const gfx::Rect& relative_to, |
| 36 BubbleBorder::ArrowLocation arrow_location) | 36 BubbleBorder::ArrowLocation arrow_location) |
| 37 : frame_(frame), | 37 : frame_(frame), |
| 38 view_(view), | 38 view_(view), |
| 39 relative_to_(relative_to), | 39 relative_to_(relative_to), |
| 40 arrow_location_(arrow_location), | 40 arrow_location_(arrow_location), |
| 41 visible_(false), | |
| 42 delegate_(NULL), | 41 delegate_(NULL), |
| 43 attached_(false), | 42 attached_(false), |
| 44 bubble_host_(GetBubbleHostFromFrame(frame)) { | 43 bubble_host_(GetBubbleHostFromFrame(frame)) { |
| 45 // Keep relative_to_ in frame-relative coordinates to aid in drag | 44 // Keep relative_to_ in frame-relative coordinates to aid in drag |
| 46 // positioning. | 45 // positioning. |
| 47 gfx::Point origin = relative_to_.origin(); | 46 gfx::Point origin = relative_to_.origin(); |
| 48 views::View::ConvertPointToView(NULL, frame_->GetRootView(), &origin); | 47 views::View::ConvertPointToView(NULL, frame_->GetRootView(), &origin); |
| 49 relative_to_.set_origin(origin); | 48 relative_to_.set_origin(origin); |
| 50 | 49 |
| 51 // Use half the corner radius as contents margins so that contents fit better | 50 // Use half the corner radius as contents margins so that contents fit better |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 bubble_host_->AttachBrowserBubble(this); | 86 bubble_host_->AttachBrowserBubble(this); |
| 88 | 87 |
| 89 attached_ = true; | 88 attached_ = true; |
| 90 } | 89 } |
| 91 | 90 |
| 92 void BrowserBubble::BrowserWindowMoved() { | 91 void BrowserBubble::BrowserWindowMoved() { |
| 93 if (delegate_) | 92 if (delegate_) |
| 94 delegate_->BubbleBrowserWindowMoved(this); | 93 delegate_->BubbleBrowserWindowMoved(this); |
| 95 else | 94 else |
| 96 Hide(); | 95 Hide(); |
| 97 if (visible_) | 96 if (popup_->IsVisible()) |
| 98 Reposition(); | 97 Reposition(); |
| 99 } | 98 } |
| 100 | 99 |
| 101 void BrowserBubble::BrowserWindowClosing() { | 100 void BrowserBubble::BrowserWindowClosing() { |
| 102 if (delegate_) | 101 if (delegate_) |
| 103 delegate_->BubbleBrowserWindowClosing(this); | 102 delegate_->BubbleBrowserWindowClosing(this); |
| 104 else | 103 else |
| 105 Hide(); | 104 Hide(); |
| 106 } | 105 } |
| 107 | 106 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 137 } | 136 } |
| 138 | 137 |
| 139 void BrowserBubble::SetAbsoluteBounds(const gfx::Rect& window_bounds) { | 138 void BrowserBubble::SetAbsoluteBounds(const gfx::Rect& window_bounds) { |
| 140 // Convert screen coordinates to frame relative. | 139 // Convert screen coordinates to frame relative. |
| 141 gfx::Point relative_origin = window_bounds.origin(); | 140 gfx::Point relative_origin = window_bounds.origin(); |
| 142 views::View::ConvertPointToView(NULL, frame_->GetRootView(), | 141 views::View::ConvertPointToView(NULL, frame_->GetRootView(), |
| 143 &relative_origin); | 142 &relative_origin); |
| 144 SetBounds(relative_origin.x(), relative_origin.y(), | 143 SetBounds(relative_origin.x(), relative_origin.y(), |
| 145 window_bounds.width(), window_bounds.height()); | 144 window_bounds.width(), window_bounds.height()); |
| 146 } | 145 } |
| 146 |
| 147 void BrowserBubble::MovePopup(int x, int y, int w, int h) { |
| 148 popup_->SetBounds(gfx::Rect(x, y, w, h)); |
| 149 } |
| 150 |
| 151 |
| OLD | NEW |