OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_actions_container.h" | 5 #include "chrome/browser/views/browser_actions_container.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "app/slide_animation.h" | 9 #include "app/slide_animation.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // This is a bit sketchy because if ImageLoadingTracker calls | 118 // This is a bit sketchy because if ImageLoadingTracker calls |
119 // ::OnImageLoaded() before our creator appends up to the view hierarchy, we | 119 // ::OnImageLoaded() before our creator appends up to the view hierarchy, we |
120 // will crash. But since we know that ImageLoadingTracker is asynchronous, | 120 // will crash. But since we know that ImageLoadingTracker is asynchronous, |
121 // this should be OK. And doing this in the constructor means that we don't | 121 // this should be OK. And doing this in the constructor means that we don't |
122 // have to protect against it getting done multiple times. | 122 // have to protect against it getting done multiple times. |
123 tracker_.LoadImage(extension->GetResource(relative_path), | 123 tracker_.LoadImage(extension->GetResource(relative_path), |
124 gfx::Size(Extension::kBrowserActionIconMaxSize, | 124 gfx::Size(Extension::kBrowserActionIconMaxSize, |
125 Extension::kBrowserActionIconMaxSize)); | 125 Extension::kBrowserActionIconMaxSize)); |
126 } | 126 } |
127 | 127 |
128 BrowserActionButton::~BrowserActionButton() { | 128 void BrowserActionButton::Destroy() { |
| 129 if (showing_context_menu_) { |
| 130 context_menu_menu_->CancelMenu(); |
| 131 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 132 } else { |
| 133 delete this; |
| 134 } |
129 } | 135 } |
130 | 136 |
131 gfx::Insets BrowserActionButton::GetInsets() const { | 137 gfx::Insets BrowserActionButton::GetInsets() const { |
132 static gfx::Insets zero_inset; | 138 static gfx::Insets zero_inset; |
133 return zero_inset; | 139 return zero_inset; |
134 } | 140 } |
135 | 141 |
136 void BrowserActionButton::ButtonPressed(views::Button* sender, | 142 void BrowserActionButton::ButtonPressed(views::Button* sender, |
137 const views::Event& event) { | 143 const views::Event& event) { |
138 panel_->OnBrowserActionExecuted(this, false); // inspect_with_devtools | 144 panel_->OnBrowserActionExecuted(this, false); // inspect_with_devtools |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // Make the menu appear below the button. | 234 // Make the menu appear below the button. |
229 point.Offset(0, height()); | 235 point.Offset(0, height()); |
230 | 236 |
231 // Reconstructs the menu every time because the menu's contents are dynamic. | 237 // Reconstructs the menu every time because the menu's contents are dynamic. |
232 context_menu_contents_.reset(new ExtensionContextMenuModel( | 238 context_menu_contents_.reset(new ExtensionContextMenuModel( |
233 extension(), panel_->browser(), panel_)); | 239 extension(), panel_->browser(), panel_)); |
234 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); | 240 context_menu_menu_.reset(new views::Menu2(context_menu_contents_.get())); |
235 context_menu_menu_->RunContextMenuAt(point); | 241 context_menu_menu_->RunContextMenuAt(point); |
236 | 242 |
237 SetButtonNotPushed(); | 243 SetButtonNotPushed(); |
| 244 showing_context_menu_ = false; |
| 245 |
238 return false; | 246 return false; |
239 } else if (IsPopup()) { | 247 } else if (IsPopup()) { |
240 return MenuButton::OnMousePressed(e); | 248 return MenuButton::OnMousePressed(e); |
241 } | 249 } |
242 return TextButton::OnMousePressed(e); | 250 return TextButton::OnMousePressed(e); |
243 } | 251 } |
244 | 252 |
245 void BrowserActionButton::OnMouseReleased(const views::MouseEvent& e, | 253 void BrowserActionButton::OnMouseReleased(const views::MouseEvent& e, |
246 bool canceled) { | 254 bool canceled) { |
247 if (IsPopup() || showing_context_menu_) { | 255 if (IsPopup() || showing_context_menu_) { |
(...skipping 21 matching lines...) Expand all Loading... |
269 void BrowserActionButton::SetButtonPushed() { | 277 void BrowserActionButton::SetButtonPushed() { |
270 SetState(views::CustomButton::BS_PUSHED); | 278 SetState(views::CustomButton::BS_PUSHED); |
271 menu_visible_ = true; | 279 menu_visible_ = true; |
272 } | 280 } |
273 | 281 |
274 void BrowserActionButton::SetButtonNotPushed() { | 282 void BrowserActionButton::SetButtonNotPushed() { |
275 SetState(views::CustomButton::BS_NORMAL); | 283 SetState(views::CustomButton::BS_NORMAL); |
276 menu_visible_ = false; | 284 menu_visible_ = false; |
277 } | 285 } |
278 | 286 |
| 287 BrowserActionButton::~BrowserActionButton() { |
| 288 } |
| 289 |
279 | 290 |
280 //////////////////////////////////////////////////////////////////////////////// | 291 //////////////////////////////////////////////////////////////////////////////// |
281 // BrowserActionView | 292 // BrowserActionView |
282 | 293 |
283 BrowserActionView::BrowserActionView(Extension* extension, | 294 BrowserActionView::BrowserActionView(Extension* extension, |
284 BrowserActionsContainer* panel) | 295 BrowserActionsContainer* panel) |
285 : panel_(panel) { | 296 : panel_(panel) { |
286 button_ = new BrowserActionButton(extension, panel); | 297 button_ = new BrowserActionButton(extension, panel); |
287 button_->SetDragController(panel_); | 298 button_->SetDragController(panel_); |
288 AddChildView(button_); | 299 AddChildView(button_); |
289 button_->UpdateState(); | 300 button_->UpdateState(); |
290 } | 301 } |
291 | 302 |
| 303 BrowserActionView::~BrowserActionView() { |
| 304 RemoveChildView(button_); |
| 305 button_->Destroy(); |
| 306 } |
| 307 |
292 gfx::Canvas* BrowserActionView::GetIconWithBadge() { | 308 gfx::Canvas* BrowserActionView::GetIconWithBadge() { |
293 int tab_id = panel_->GetCurrentTabId(); | 309 int tab_id = panel_->GetCurrentTabId(); |
294 | 310 |
295 SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); | 311 SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); |
296 if (icon.isNull()) | 312 if (icon.isNull()) |
297 icon = button_->default_icon(); | 313 icon = button_->default_icon(); |
298 | 314 |
299 gfx::Canvas* canvas = new gfx::Canvas(icon.width(), icon.height(), false); | 315 gfx::Canvas* canvas = new gfx::Canvas(icon.width(), icon.height(), false); |
300 canvas->DrawBitmapInt(icon, 0, 0); | 316 canvas->DrawBitmapInt(icon, 0, 0); |
301 | 317 |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 popup_ = NULL; | 1134 popup_ = NULL; |
1119 popup_button_->SetButtonNotPushed(); | 1135 popup_button_->SetButtonNotPushed(); |
1120 popup_button_ = NULL; | 1136 popup_button_ = NULL; |
1121 } | 1137 } |
1122 | 1138 |
1123 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { | 1139 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { |
1124 // Only display incognito-enabled extensions while in incognito mode. | 1140 // Only display incognito-enabled extensions while in incognito mode. |
1125 return (!profile_->IsOffTheRecord() || | 1141 return (!profile_->IsOffTheRecord() || |
1126 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); | 1142 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); |
1127 } | 1143 } |
OLD | NEW |