| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "chrome/browser/ui/views/bubble/border_contents.h" | 9 #include "chrome/browser/ui/views/bubble/border_contents.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" | 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 11 #include "views/widget/root_view.h" | 11 #include "views/widget/root_view.h" |
| 12 #include "views/widget/widget_gtk.h" | 12 #include "views/widget/widget_gtk.h" |
| 13 | 13 |
| 14 #if defined(OS_CHROMEOS) | 14 #if defined(OS_CHROMEOS) |
| 15 #include "chrome/browser/chromeos/wm_ipc.h" | 15 #include "chrome/browser/chromeos/wm_ipc.h" |
| 16 #include "third_party/cros/chromeos_wm_ipc_enums.h" | 16 #include "third_party/cros/chromeos_wm_ipc_enums.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 using std::vector; | 19 using std::vector; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class BubbleWidget : public views::WidgetGtk { | 23 class BubbleWidget : public views::WidgetGtk { |
| 24 public: | 24 public: |
| 25 BubbleWidget(BrowserBubble* bubble, const gfx::Insets& content_margins) | 25 BubbleWidget(BrowserBubble* bubble, const gfx::Insets& content_margins) |
| 26 : bubble_(bubble), | 26 : views::WidgetGtk(new views::Widget), |
| 27 bubble_(bubble), |
| 27 border_contents_(new BorderContents) { | 28 border_contents_(new BorderContents) { |
| 28 border_contents_->Init(); | 29 border_contents_->Init(); |
| 29 border_contents_->set_content_margins(content_margins); | 30 border_contents_->set_content_margins(content_margins); |
| 30 } | 31 } |
| 31 | 32 |
| 32 void ShowAndActivate(bool activate) { | 33 void ShowAndActivate(bool activate) { |
| 33 // TODO: honor activate. | 34 // TODO: honor activate. |
| 34 views::WidgetGtk::Show(); | 35 views::WidgetGtk::Show(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 virtual void Close() { | 38 virtual void Close() { |
| 38 if (!bubble_) | 39 if (!bubble_) |
| 39 return; // We have already been closed. | 40 return; // We have already been closed. |
| 40 if (IsActive()) { | 41 if (IsActive()) { |
| 41 BrowserBubble::Delegate* delegate = bubble_->delegate(); | 42 BrowserBubble::Delegate* delegate = bubble_->delegate(); |
| 42 if (delegate) | 43 if (delegate) |
| 43 delegate->BubbleLostFocus(bubble_, false); | 44 delegate->BubbleLostFocus(bubble_, false); |
| 44 } | 45 } |
| 45 views::WidgetGtk::Close(); | 46 views::WidgetGtk::Close(); |
| 46 bubble_ = NULL; | 47 bubble_ = NULL; |
| 47 } | 48 } |
| 48 | 49 |
| 49 virtual void Hide() { | 50 virtual void Hide() { |
| 50 if (IsActive()&& bubble_) { | 51 if (IsActive() && bubble_) { |
| 51 BrowserBubble::Delegate* delegate = bubble_->delegate(); | 52 BrowserBubble::Delegate* delegate = bubble_->delegate(); |
| 52 if (delegate) | 53 if (delegate) |
| 53 delegate->BubbleLostFocus(bubble_, false); | 54 delegate->BubbleLostFocus(bubble_, false); |
| 54 } | 55 } |
| 55 views::WidgetGtk::Hide(); | 56 views::WidgetGtk::Hide(); |
| 56 } | 57 } |
| 57 | 58 |
| 58 virtual void IsActiveChanged() { | 59 virtual void IsActiveChanged() { |
| 59 if (IsActive() || !bubble_) | 60 if (IsActive() || !bubble_) |
| 60 return; | 61 return; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 85 BrowserBubble* bubble_; | 86 BrowserBubble* bubble_; |
| 86 BorderContents* border_contents_; // Owned by root view of this widget. | 87 BorderContents* border_contents_; // Owned by root view of this widget. |
| 87 | 88 |
| 88 DISALLOW_COPY_AND_ASSIGN(BubbleWidget); | 89 DISALLOW_COPY_AND_ASSIGN(BubbleWidget); |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 } // namespace | 92 } // namespace |
| 92 | 93 |
| 93 void BrowserBubble::InitPopup(const gfx::Insets& content_margins) { | 94 void BrowserBubble::InitPopup(const gfx::Insets& content_margins) { |
| 94 // TODO(port) | 95 // TODO(port) |
| 95 BubbleWidget* pop = new BubbleWidget(this, content_margins); | 96 BubbleWidget* bubble_widget = new BubbleWidget(this, content_margins); |
| 96 pop->MakeTransparent(); | 97 popup_ = bubble_widget->GetWidget(); |
| 97 pop->make_transient_to_parent(); | |
| 98 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 98 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 99 params.transparent = true; |
| 99 params.parent = frame_->GetNativeView(); | 100 params.parent = frame_->GetNativeView(); |
| 100 pop->Init(params); | 101 params.native_widget = bubble_widget; |
| 102 popup_->Init(params); |
| 101 #if defined(OS_CHROMEOS) | 103 #if defined(OS_CHROMEOS) |
| 102 { | 104 { |
| 103 vector<int> params; | 105 vector<int> params; |
| 104 params.push_back(0); // don't show while screen is locked | 106 params.push_back(0); // don't show while screen is locked |
| 105 chromeos::WmIpc::instance()->SetWindowType( | 107 chromeos::WmIpc::instance()->SetWindowType( |
| 106 pop->GetNativeView(), | 108 popup_->GetNativeView(), |
| 107 chromeos::WM_IPC_WINDOW_CHROME_INFO_BUBBLE, | 109 chromeos::WM_IPC_WINDOW_CHROME_INFO_BUBBLE, |
| 108 ¶ms); | 110 ¶ms); |
| 109 } | 111 } |
| 110 #endif | 112 #endif |
| 111 | 113 |
| 112 views::View* contents_view = new views::View; | 114 views::View* contents_view = new views::View; |
| 113 | 115 |
| 114 // We add |contents_view| to ourselves before the AddChildView() call below so | 116 // We add |contents_view| to ourselves before the AddChildView() call below so |
| 115 // that when |contents| gets added, it will already have a widget, and thus | 117 // that when |contents| gets added, it will already have a widget, and thus |
| 116 // any NativeButtons it creates in ViewHierarchyChanged() will be functional | 118 // any NativeButtons it creates in ViewHierarchyChanged() will be functional |
| 117 // (e.g. calling SetChecked() on checkboxes is safe). | 119 // (e.g. calling SetChecked() on checkboxes is safe). |
| 118 pop->SetContentsView(contents_view); | 120 popup_->SetContentsView(contents_view); |
| 119 | 121 |
| 120 // Added border_contents before |view_| so it will paint under it. | 122 // Added border_contents before |view_| so it will paint under it. |
| 121 contents_view->AddChildView(pop->border_contents()); | 123 contents_view->AddChildView(bubble_widget->border_contents()); |
| 122 contents_view->AddChildView(view_); | 124 contents_view->AddChildView(view_); |
| 123 | 125 |
| 124 popup_ = pop; | |
| 125 | |
| 126 ResizeToView(); | 126 ResizeToView(); |
| 127 Reposition(); | 127 Reposition(); |
| 128 AttachToBrowser(); | 128 AttachToBrowser(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void BrowserBubble::MovePopup(int x, int y, int w, int h) { | |
| 132 views::WidgetGtk* pop = static_cast<views::WidgetGtk*>(popup_); | |
| 133 pop->SetBounds(gfx::Rect(x, y, w, h)); | |
| 134 } | |
| 135 | |
| 136 void BrowserBubble::Show(bool activate) { | 131 void BrowserBubble::Show(bool activate) { |
| 137 if (visible_) | 132 if (!popup_->IsVisible()) { |
| 138 return; | 133 static_cast<BubbleWidget*>(popup_->native_widget())->ShowAndActivate( |
| 139 static_cast<BubbleWidget*>(popup_)->ShowAndActivate(activate); | 134 activate); |
| 140 visible_ = true; | 135 } |
| 141 } | 136 } |
| 142 | 137 |
| 143 void BrowserBubble::Hide() { | 138 void BrowserBubble::Hide() { |
| 144 if (!visible_) | 139 if (popup_->IsVisible()) |
| 145 return; | 140 static_cast<BubbleWidget*>(popup_->native_widget())->Hide(); |
| 146 views::WidgetGtk* pop = static_cast<views::WidgetGtk*>(popup_); | |
| 147 pop->Hide(); | |
| 148 visible_ = false; | |
| 149 } | 141 } |
| 150 | 142 |
| 151 void BrowserBubble::ResizeToView() { | 143 void BrowserBubble::ResizeToView() { |
| 152 BorderContents* border_contents = | 144 BorderContents* border_contents = |
| 153 static_cast<BubbleWidget*>(popup_)->border_contents(); | 145 static_cast<BubbleWidget*>(popup_->native_widget())->border_contents(); |
| 154 | 146 |
| 155 // Calculate and set the bounds for all windows and views. | 147 // Calculate and set the bounds for all windows and views. |
| 156 gfx::Rect window_bounds; | 148 gfx::Rect window_bounds; |
| 157 gfx::Rect contents_bounds; | 149 gfx::Rect contents_bounds; |
| 158 border_contents->SizeAndGetBounds(GetAbsoluteRelativeTo(), | 150 border_contents->SizeAndGetBounds(GetAbsoluteRelativeTo(), |
| 159 arrow_location_, false, view_->size(), | 151 arrow_location_, false, view_->size(), |
| 160 &contents_bounds, &window_bounds); | 152 &contents_bounds, &window_bounds); |
| 161 | 153 |
| 162 border_contents->SetBoundsRect(gfx::Rect(gfx::Point(), window_bounds.size())); | 154 border_contents->SetBoundsRect(gfx::Rect(gfx::Point(), window_bounds.size())); |
| 163 view_->SetBoundsRect(contents_bounds); | 155 view_->SetBoundsRect(contents_bounds); |
| 164 | 156 |
| 165 SetAbsoluteBounds(window_bounds); | 157 SetAbsoluteBounds(window_bounds); |
| 166 } | 158 } |
| OLD | NEW |