Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: chrome/browser/views/browser_bubble.cc

Issue 119103: Part 1 of dragging extensions on the shelf. This part was just about getting... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/browser_bubble.h ('k') | chrome/browser/views/browser_bubble_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "views/widget/root_view.h" 9 #include "views/widget/root_view.h"
9 10
10 BrowserBubble::BrowserBubble(views::View* view, views::Widget* frame, 11 BrowserBubble::BrowserBubble(views::View* view, views::Widget* frame,
11 const gfx::Point& origin) 12 const gfx::Point& origin)
12 : frame_(frame), 13 : frame_(frame),
13 view_(view), 14 view_(view),
14 visible_(false), 15 visible_(false),
15 delegate_(NULL) { 16 delegate_(NULL),
17 attached_(false) {
18 frame_native_view_ = frame_->GetNativeView();
16 gfx::Size size = view->GetPreferredSize(); 19 gfx::Size size = view->GetPreferredSize();
17 bounds_.SetRect(origin.x(), origin.y(), size.width(), size.height()); 20 bounds_.SetRect(origin.x(), origin.y(), size.width(), size.height());
18 InitPopup(); 21 InitPopup();
19 } 22 }
20 23
21 BrowserBubble::~BrowserBubble() { 24 BrowserBubble::~BrowserBubble() {
22 DestroyPopup(); 25 DCHECK(!attached_);
26 popup_->CloseNow();
27 // Don't call DetachFromBrowser from here. It needs to talk to the
28 // BrowserView to deregister itself, and if BrowserBubble is owned
29 // by a child of BrowserView, then it's possible that this stack frame
30 // is a descendant of BrowserView's destructor, which leads to problems.
31 // In that case, Detach doesn't need to get called anyway since BrowserView
32 // will do the necessary cleanup.
33 }
34
35 void BrowserBubble::DetachFromBrowser() {
36 DCHECK(attached_);
37 if (!attached_)
38 return;
39 attached_ = false;
40 BrowserView* browser_view =
41 BrowserView::GetBrowserViewForNativeWindow(frame_native_view_);
42 if (browser_view)
43 browser_view->DetachBrowserBubble(this);
44 }
45
46 void BrowserBubble::AttachToBrowser() {
47 DCHECK(!attached_);
48 if (attached_)
49 return;
50 BrowserView* browser_view =
51 BrowserView::GetBrowserViewForNativeWindow(frame_native_view_);
52 DCHECK(browser_view);
53 if (browser_view) {
54 browser_view->AttachBrowserBubble(this);
55 attached_ = true;
56 }
23 } 57 }
24 58
25 void BrowserBubble::BrowserWindowMoved() { 59 void BrowserBubble::BrowserWindowMoved() {
26 if (delegate_) 60 if (delegate_)
27 delegate_->BubbleBrowserWindowMoved(this); 61 delegate_->BubbleBrowserWindowMoved(this);
28 else 62 else
29 Hide(); 63 Hide();
30 } 64 }
31 65
32 void BrowserBubble::BrowserWindowClosed() { 66 void BrowserBubble::BrowserWindowClosed() {
33 if (delegate_) 67 if (delegate_)
34 delegate_->BubbleBrowserWindowClosed(this); 68 delegate_->BubbleBrowserWindowClosed(this);
35 else 69 else
36 Hide(); 70 Hide();
37 } 71 }
38 72
39 void BrowserBubble::SetBounds(int x, int y, int w, int h) { 73 void BrowserBubble::SetBounds(int x, int y, int w, int h) {
40 // If the UI layout is RTL, we need to mirror the position of the bubble 74 // If the UI layout is RTL, we need to mirror the position of the bubble
41 // relative to the parent. 75 // relative to the parent.
42 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { 76 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
43 gfx::Rect frame_bounds; 77 gfx::Rect frame_bounds;
44 frame_->GetBounds(&frame_bounds, false); 78 frame_->GetBounds(&frame_bounds, false);
45 x = frame_bounds.width() - x - w; 79 x = frame_bounds.width() - x - w;
46 } 80 }
47 bounds_.SetRect(x, y, w, h); 81 bounds_.SetRect(x, y, w, h);
48 Reposition(); 82 Reposition();
49 } 83 }
50 84
85 void BrowserBubble::MoveTo(int x, int y) {
86 SetBounds(x, y, bounds_.width(), bounds_.height());
87 }
88
51 void BrowserBubble::Reposition() { 89 void BrowserBubble::Reposition() {
52 gfx::Point top_left; 90 gfx::Point top_left;
53 views::View::ConvertPointToScreen(frame_->GetRootView(), &top_left); 91 views::View::ConvertPointToScreen(frame_->GetRootView(), &top_left);
54 MovePopup(top_left.x() + bounds_.x(), 92 MovePopup(top_left.x() + bounds_.x(),
55 top_left.y() + bounds_.y(), 93 top_left.y() + bounds_.y(),
56 bounds_.width(), 94 bounds_.width(),
57 bounds_.height()); 95 bounds_.height());
58 } 96 }
97
98 void BrowserBubble::ResizeToView() {
99 gfx::Size size = view_->GetPreferredSize();
100 SetBounds(bounds_.x(), bounds_.y(), size.width(), size.height());
101 }
102
OLDNEW
« no previous file with comments | « chrome/browser/views/browser_bubble.h ('k') | chrome/browser/views/browser_bubble_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698