| 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/browser.h" |
| 7 #include "chrome/browser/ui/views/frame/browser_view.h" | 8 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 8 #include "views/widget/widget.h" | 9 #include "views/widget/widget.h" |
| 9 | 10 |
| 10 namespace { | 11 BrowserBubble::BrowserBubble(Browser* browser, |
| 11 | 12 views::View* view, |
| 12 BrowserBubbleHost* GetBubbleHostFromFrame(views::Widget* frame) { | |
| 13 if (!frame) | |
| 14 return NULL; | |
| 15 | |
| 16 BrowserBubbleHost* bubble_host = NULL; | |
| 17 views::Widget* window = frame->GetTopLevelWidget(); | |
| 18 if (window) { | |
| 19 bubble_host = BrowserView::GetBrowserViewForNativeWindow( | |
| 20 window->GetNativeWindow()); | |
| 21 DCHECK(bubble_host); | |
| 22 } | |
| 23 | |
| 24 return bubble_host; | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 BrowserBubble::BrowserBubble(views::View* view, | |
| 30 views::Widget* frame, | |
| 31 const gfx::Rect& relative_to, | 13 const gfx::Rect& relative_to, |
| 32 views::BubbleBorder::ArrowLocation arrow_location) | 14 views::BubbleBorder::ArrowLocation arrow_location) |
| 33 : frame_(frame), | 15 : frame_(NULL), |
| 34 view_(view), | 16 view_(view), |
| 35 relative_to_(relative_to), | 17 relative_to_(relative_to), |
| 36 arrow_location_(arrow_location), | 18 arrow_location_(arrow_location), |
| 37 delegate_(NULL), | 19 delegate_(NULL), |
| 38 attached_(false), | 20 attached_(false), |
| 39 bubble_host_(GetBubbleHostFromFrame(frame)) { | 21 bubble_host_(NULL) { |
| 22 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
| 23 frame_ = browser_view->GetWidget(); |
| 24 bubble_host_ = browser_view; |
| 40 // Keep relative_to_ in frame-relative coordinates to aid in drag | 25 // Keep relative_to_ in frame-relative coordinates to aid in drag |
| 41 // positioning. | 26 // positioning. |
| 42 gfx::Point origin = relative_to_.origin(); | 27 gfx::Point origin = relative_to_.origin(); |
| 43 views::View::ConvertPointToView(NULL, frame_->GetRootView(), &origin); | 28 views::View::ConvertPointToView(NULL, frame_->GetRootView(), &origin); |
| 44 relative_to_.set_origin(origin); | 29 relative_to_.set_origin(origin); |
| 45 | 30 |
| 46 // Use half the corner radius as contents margins so that contents fit better | 31 // Use half the corner radius as contents margins so that contents fit better |
| 47 // in the bubble. See http://crbug.com/80416. | 32 // in the bubble. See http://crbug.com/80416. |
| 48 int corner_inset = views::BubbleBorder::GetCornerRadius() / 2; | 33 int corner_inset = views::BubbleBorder::GetCornerRadius() / 2; |
| 49 gfx::Insets content_margins(corner_inset, corner_inset, | 34 gfx::Insets content_margins(corner_inset, corner_inset, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 gfx::Point relative_origin = window_bounds.origin(); | 121 gfx::Point relative_origin = window_bounds.origin(); |
| 137 views::View::ConvertPointToView(NULL, frame_->GetRootView(), | 122 views::View::ConvertPointToView(NULL, frame_->GetRootView(), |
| 138 &relative_origin); | 123 &relative_origin); |
| 139 SetBounds(relative_origin.x(), relative_origin.y(), | 124 SetBounds(relative_origin.x(), relative_origin.y(), |
| 140 window_bounds.width(), window_bounds.height()); | 125 window_bounds.width(), window_bounds.height()); |
| 141 } | 126 } |
| 142 | 127 |
| 143 void BrowserBubble::MovePopup(int x, int y, int w, int h) { | 128 void BrowserBubble::MovePopup(int x, int y, int w, int h) { |
| 144 popup_->SetBounds(gfx::Rect(x, y, w, h)); | 129 popup_->SetBounds(gfx::Rect(x, y, w, h)); |
| 145 } | 130 } |
| OLD | NEW |