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/extensions/extension_installed_bubble.h" | 5 #include "chrome/browser/ui/views/extensions/extension_installed_bubble.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/ui/views/toolbar_view.h" | 22 #include "chrome/browser/ui/views/toolbar_view.h" |
23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
24 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
25 #include "chrome/common/extensions/extension_action.h" | 25 #include "chrome/common/extensions/extension_action.h" |
26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
27 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
29 #include "grit/theme_resources_standard.h" | 29 #include "grit/theme_resources_standard.h" |
30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
32 #include "ui/views/layout/fill_layout.h" | |
33 #include "ui/views/layout/layout_constants.h" | 32 #include "ui/views/layout/layout_constants.h" |
34 #include "views/controls/button/image_button.h" | 33 #include "views/controls/button/image_button.h" |
35 #include "views/controls/image_view.h" | 34 #include "views/controls/image_view.h" |
36 #include "views/controls/label.h" | 35 #include "views/controls/label.h" |
37 #include "views/controls/link.h" | 36 #include "views/controls/link.h" |
38 #include "views/controls/link_listener.h" | 37 #include "views/controls/link_listener.h" |
39 #include "views/view.h" | 38 #include "views/view.h" |
40 | 39 |
41 namespace { | 40 namespace { |
42 | 41 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 // InstalledBubbleContent is the content view which is placed in the | 83 // InstalledBubbleContent is the content view which is placed in the |
85 // ExtensionInstalledBubble. It displays the install icon and explanatory | 84 // ExtensionInstalledBubble. It displays the install icon and explanatory |
86 // text about the installed extension. | 85 // text about the installed extension. |
87 class InstalledBubbleContent : public views::View, | 86 class InstalledBubbleContent : public views::View, |
88 public views::ButtonListener, | 87 public views::ButtonListener, |
89 public views::LinkListener { | 88 public views::LinkListener { |
90 public: | 89 public: |
91 InstalledBubbleContent(Browser* browser, | 90 InstalledBubbleContent(Browser* browser, |
92 const Extension* extension, | 91 const Extension* extension, |
93 ExtensionInstalledBubble::BubbleType type, | 92 ExtensionInstalledBubble::BubbleType type, |
94 SkBitmap* icon, | 93 SkBitmap* icon) |
95 ExtensionInstalledBubble* bubble) | |
96 : browser_(browser), | 94 : browser_(browser), |
97 extension_id_(extension->id()), | 95 extension_id_(extension->id()), |
98 bubble_(bubble), | 96 bubble_(NULL), |
99 type_(type), | 97 type_(type), |
100 info_(NULL) { | 98 info_(NULL) { |
101 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 99 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
102 const gfx::Font& font = rb.GetFont(ResourceBundle::BaseFont); | 100 const gfx::Font& font = rb.GetFont(ResourceBundle::BaseFont); |
103 | 101 |
104 // Scale down to 43x43, but allow smaller icons (don't scale up). | 102 // Scale down to 43x43, but allow smaller icons (don't scale up). |
105 gfx::Size size(icon->width(), icon->height()); | 103 gfx::Size size(icon->width(), icon->height()); |
106 if (size.width() > kIconSize || size.height() > kIconSize) | 104 if (size.width() > kIconSize || size.height() > kIconSize) |
107 size = gfx::Size(kIconSize, kIconSize); | 105 size = gfx::Size(kIconSize, kIconSize); |
108 icon_ = new views::ImageView(); | 106 icon_ = new views::ImageView(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 close_button_ = new views::ImageButton(this); | 165 close_button_ = new views::ImageButton(this); |
168 close_button_->SetImage(views::CustomButton::BS_NORMAL, | 166 close_button_->SetImage(views::CustomButton::BS_NORMAL, |
169 rb.GetBitmapNamed(IDR_CLOSE_BAR)); | 167 rb.GetBitmapNamed(IDR_CLOSE_BAR)); |
170 close_button_->SetImage(views::CustomButton::BS_HOT, | 168 close_button_->SetImage(views::CustomButton::BS_HOT, |
171 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); | 169 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); |
172 close_button_->SetImage(views::CustomButton::BS_PUSHED, | 170 close_button_->SetImage(views::CustomButton::BS_PUSHED, |
173 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); | 171 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); |
174 AddChildView(close_button_); | 172 AddChildView(close_button_); |
175 } | 173 } |
176 | 174 |
177 virtual void ButtonPressed(views::Button* sender, const views::Event& event) { | 175 void set_bubble(Bubble* bubble) { bubble_ = bubble; } |
178 if (sender == close_button_) | 176 |
179 bubble_->StartFade(false); | 177 virtual void ButtonPressed( |
180 else | 178 views::Button* sender, |
| 179 const views::Event& event) { |
| 180 if (sender == close_button_) { |
| 181 bubble_->set_fade_away_on_close(true); |
| 182 GetWidget()->Close(); |
| 183 } else { |
181 NOTREACHED() << "Unknown view"; | 184 NOTREACHED() << "Unknown view"; |
| 185 } |
182 } | 186 } |
183 | 187 |
184 // Implements the views::LinkListener interface. | 188 // Implements the views::LinkListener interface. |
185 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { | 189 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { |
186 GetWidget()->Close(); | 190 GetWidget()->Close(); |
187 ExtensionInstallUI::OpenAppInstalledNTP(browser_, extension_id_); | 191 ExtensionInstallUI::OpenAppInstalledNTP(browser_, extension_id_); |
188 } | 192 } |
189 | 193 |
190 private: | 194 private: |
191 virtual gfx::Size GetPreferredSize() { | 195 virtual gfx::Size GetPreferredSize() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 // title text and bubble arrow. | 251 // title text and bubble arrow. |
248 close_button_->SetBounds(x - 1, y - 1, sz.width(), sz.height()); | 252 close_button_->SetBounds(x - 1, y - 1, sz.width(), sz.height()); |
249 } | 253 } |
250 | 254 |
251 // The browser we're associated with. | 255 // The browser we're associated with. |
252 Browser* browser_; | 256 Browser* browser_; |
253 | 257 |
254 // The id of the extension just installed. | 258 // The id of the extension just installed. |
255 const std::string extension_id_; | 259 const std::string extension_id_; |
256 | 260 |
257 // The ExtensionInstalledBubble showing us. | 261 // The Bubble showing us. |
258 ExtensionInstalledBubble* bubble_; | 262 Bubble* bubble_; |
259 | 263 |
260 ExtensionInstalledBubble::BubbleType type_; | 264 ExtensionInstalledBubble::BubbleType type_; |
261 views::ImageView* icon_; | 265 views::ImageView* icon_; |
262 views::Label* heading_; | 266 views::Label* heading_; |
263 views::Label* info_; | 267 views::Label* info_; |
264 views::Label* manage_; | 268 views::Label* manage_; |
265 views::ImageButton* close_button_; | 269 views::ImageButton* close_button_; |
266 | 270 |
267 DISALLOW_COPY_AND_ASSIGN(InstalledBubbleContent); | 271 DISALLOW_COPY_AND_ASSIGN(InstalledBubbleContent); |
268 }; | 272 }; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 if (extension == extension_) | 332 if (extension == extension_) |
329 extension_ = NULL; | 333 extension_ = NULL; |
330 } else { | 334 } else { |
331 NOTREACHED() << L"Received unexpected notification"; | 335 NOTREACHED() << L"Received unexpected notification"; |
332 } | 336 } |
333 } | 337 } |
334 | 338 |
335 void ExtensionInstalledBubble::ShowInternal() { | 339 void ExtensionInstalledBubble::ShowInternal() { |
336 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 340 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
337 | 341 |
338 views::View* reference_view = NULL; | 342 const views::View* reference_view = NULL; |
339 if (type_ == APP) { | 343 if (type_ == APP) { |
340 if (browser_view->IsTabStripVisible()) { | 344 if (browser_view->IsTabStripVisible()) { |
341 AbstractTabStripView* tabstrip = browser_view->tabstrip(); | 345 AbstractTabStripView* tabstrip = browser_view->tabstrip(); |
342 views::View* ntp_button = tabstrip->GetNewTabButton(); | 346 views::View* ntp_button = tabstrip->GetNewTabButton(); |
343 if (ntp_button && ntp_button->IsVisibleInRootView()) { | 347 if (ntp_button && ntp_button->IsVisibleInRootView()) { |
344 reference_view = ntp_button; | 348 reference_view = ntp_button; |
345 } else { | 349 } else { |
346 // Just have the bubble point at the tab strip. | 350 // Just have the bubble point at the tab strip. |
347 reference_view = tabstrip; | 351 reference_view = tabstrip; |
348 } | 352 } |
(...skipping 30 matching lines...) Expand all Loading... |
379 DCHECK(reference_view); | 383 DCHECK(reference_view); |
380 } else if (type_ == OMNIBOX_KEYWORD) { | 384 } else if (type_ == OMNIBOX_KEYWORD) { |
381 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); | 385 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); |
382 reference_view = location_bar_view; | 386 reference_view = location_bar_view; |
383 DCHECK(reference_view); | 387 DCHECK(reference_view); |
384 } | 388 } |
385 | 389 |
386 // Default case. | 390 // Default case. |
387 if (reference_view == NULL) | 391 if (reference_view == NULL) |
388 reference_view = browser_view->GetToolbarView()->app_menu(); | 392 reference_view = browser_view->GetToolbarView()->app_menu(); |
389 set_anchor_view(reference_view); | |
390 | 393 |
391 SetLayoutManager(new views::FillLayout()); | 394 gfx::Point origin; |
392 AddChildView( | 395 views::View::ConvertPointToScreen(reference_view, &origin); |
393 new InstalledBubbleContent(browser_, extension_, type_, &icon_, this)); | 396 gfx::Rect bounds = reference_view->bounds(); |
394 views::BubbleDelegateView::CreateBubble(this); | 397 bounds.set_origin(origin); |
395 StartFade(true); | 398 views::BubbleBorder::ArrowLocation arrow_location = |
396 } | 399 views::BubbleBorder::TOP_RIGHT; |
397 | 400 |
398 gfx::Point ExtensionInstalledBubble::GetAnchorPoint() { | |
399 // For omnibox keyword bubbles, move the arrow to point to the left edge | 401 // For omnibox keyword bubbles, move the arrow to point to the left edge |
400 // of the omnibox, just to the right of the icon. | 402 // of the omnibox, just to the right of the icon. |
401 if (type_ == OMNIBOX_KEYWORD) { | 403 if (type_ == OMNIBOX_KEYWORD) { |
402 LocationBarView* location_bar_view = | 404 bounds.set_origin( |
403 BrowserView::GetBrowserViewForBrowser(browser_)->GetLocationBarView(); | 405 browser_view->GetLocationBarView()->GetLocationEntryOrigin()); |
404 return location_bar_view->GetLocationEntryOrigin().Add( | 406 bounds.set_width(0); |
405 gfx::Point(0, location_bar_view->location_entry_view()->height())); | 407 arrow_location = views::BubbleBorder::TOP_LEFT; |
406 } | 408 } |
407 return views::BubbleDelegateView::GetAnchorPoint(); | 409 |
| 410 bubble_content_ = new InstalledBubbleContent( |
| 411 browser_, extension_, type_, &icon_); |
| 412 Bubble* bubble = Bubble::Show(browser_view->GetWidget(), bounds, |
| 413 arrow_location, |
| 414 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, |
| 415 bubble_content_, this); |
| 416 bubble_content_->set_bubble(bubble); |
408 } | 417 } |
409 | 418 |
410 views::BubbleBorder::ArrowLocation | 419 // BubbleDelegate |
411 ExtensionInstalledBubble::GetArrowLocation() const { | 420 void ExtensionInstalledBubble::BubbleClosing(Bubble* bubble, |
412 return type_ == OMNIBOX_KEYWORD ? views::BubbleBorder::TOP_LEFT : | 421 bool closed_by_escape) { |
413 views::BubbleBorder::TOP_RIGHT; | |
414 } | |
415 | |
416 void ExtensionInstalledBubble::WindowClosing() { | |
417 if (extension_ && type_ == PAGE_ACTION) { | 422 if (extension_ && type_ == PAGE_ACTION) { |
418 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 423 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
419 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( | 424 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( |
420 extension_->page_action(), | 425 extension_->page_action(), |
421 false); // preview_enabled | 426 false); // preview_enabled |
422 } | 427 } |
423 | 428 |
424 Release(); // Balanced in ctor. | 429 Release(); // Balanced in ctor. |
425 } | 430 } |
| 431 |
| 432 bool ExtensionInstalledBubble::CloseOnEscape() { |
| 433 return true; |
| 434 } |
| 435 |
| 436 bool ExtensionInstalledBubble::FadeInOnShow() { |
| 437 return true; |
| 438 } |
OLD | NEW |