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/gtk/location_bar_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "chrome/browser/ui/gtk/rounded_window.h" | 47 #include "chrome/browser/ui/gtk/rounded_window.h" |
48 #include "chrome/browser/ui/gtk/view_id_util.h" | 48 #include "chrome/browser/ui/gtk/view_id_util.h" |
49 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 49 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
50 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 50 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
51 #include "chrome/common/chrome_notification_types.h" | 51 #include "chrome/common/chrome_notification_types.h" |
52 #include "chrome/common/extensions/extension.h" | 52 #include "chrome/common/extensions/extension.h" |
53 #include "chrome/common/extensions/extension_action.h" | 53 #include "chrome/common/extensions/extension_action.h" |
54 #include "chrome/common/extensions/extension_resource.h" | 54 #include "chrome/common/extensions/extension_resource.h" |
55 #include "chrome/common/pref_names.h" | 55 #include "chrome/common/pref_names.h" |
56 #include "content/browser/tab_contents/tab_contents.h" | 56 #include "content/browser/tab_contents/tab_contents.h" |
57 #include "content/common/notification_service.h" | 57 #include "content/public/browser/notification_service.h" |
58 #include "grit/generated_resources.h" | 58 #include "grit/generated_resources.h" |
59 #include "grit/theme_resources.h" | 59 #include "grit/theme_resources.h" |
60 #include "grit/theme_resources_standard.h" | 60 #include "grit/theme_resources_standard.h" |
61 #include "net/base/net_util.h" | 61 #include "net/base/net_util.h" |
62 #include "ui/base/dragdrop/gtk_dnd_util.h" | 62 #include "ui/base/dragdrop/gtk_dnd_util.h" |
63 #include "ui/base/gtk/gtk_hig_constants.h" | 63 #include "ui/base/gtk/gtk_hig_constants.h" |
64 #include "ui/base/l10n/l10n_util.h" | 64 #include "ui/base/l10n/l10n_util.h" |
65 #include "ui/base/resource/resource_bundle.h" | 65 #include "ui/base/resource/resource_bundle.h" |
66 #include "ui/gfx/canvas_skia_paint.h" | 66 #include "ui/gfx/canvas_skia_paint.h" |
67 #include "ui/gfx/font.h" | 67 #include "ui/gfx/font.h" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 Update(NULL); | 546 Update(NULL); |
547 } | 547 } |
548 | 548 |
549 void LocationBarViewGtk::OnKillFocus() { | 549 void LocationBarViewGtk::OnKillFocus() { |
550 } | 550 } |
551 | 551 |
552 void LocationBarViewGtk::OnSetFocus() { | 552 void LocationBarViewGtk::OnSetFocus() { |
553 Profile* profile = browser_->profile(); | 553 Profile* profile = browser_->profile(); |
554 AccessibilityTextBoxInfo info(profile, | 554 AccessibilityTextBoxInfo info(profile, |
555 l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION), false); | 555 l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION), false); |
556 NotificationService::current()->Notify( | 556 content::NotificationService::current()->Notify( |
557 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, | 557 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, |
558 content::Source<Profile>(profile), | 558 content::Source<Profile>(profile), |
559 content::Details<AccessibilityTextBoxInfo>(&info)); | 559 content::Details<AccessibilityTextBoxInfo>(&info)); |
560 | 560 |
561 // Update the keyword and search hint states. | 561 // Update the keyword and search hint states. |
562 OnChanged(); | 562 OnChanged(); |
563 } | 563 } |
564 | 564 |
565 SkBitmap LocationBarViewGtk::GetFavicon() const { | 565 SkBitmap LocationBarViewGtk::GetFavicon() const { |
566 return GetTabContentsWrapper()->favicon_tab_helper()->GetFavicon(); | 566 return GetTabContentsWrapper()->favicon_tab_helper()->GetFavicon(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 // loaded or added after startup. | 652 // loaded or added after startup. |
653 if (page_actions.size() != page_action_views_.size()) { | 653 if (page_actions.size() != page_action_views_.size()) { |
654 page_action_views_.reset(); // Delete the old views (if any). | 654 page_action_views_.reset(); // Delete the old views (if any). |
655 | 655 |
656 for (size_t i = 0; i < page_actions.size(); ++i) { | 656 for (size_t i = 0; i < page_actions.size(); ++i) { |
657 page_action_views_.push_back( | 657 page_action_views_.push_back( |
658 new PageActionViewGtk(this, page_actions[i])); | 658 new PageActionViewGtk(this, page_actions[i])); |
659 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), | 659 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), |
660 page_action_views_[i]->widget(), FALSE, FALSE, 0); | 660 page_action_views_[i]->widget(), FALSE, FALSE, 0); |
661 } | 661 } |
662 NotificationService::current()->Notify( | 662 content::NotificationService::current()->Notify( |
663 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 663 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
664 content::Source<LocationBar>(this), | 664 content::Source<LocationBar>(this), |
665 NotificationService::NoDetails()); | 665 content::NotificationService::NoDetails()); |
666 } | 666 } |
667 | 667 |
668 TabContents* contents = GetTabContents(); | 668 TabContents* contents = GetTabContents(); |
669 if (!page_action_views_.empty() && contents) { | 669 if (!page_action_views_.empty() && contents) { |
670 GURL url = GURL(toolbar_model_->GetText()); | 670 GURL url = GURL(toolbar_model_->GetText()); |
671 | 671 |
672 for (size_t i = 0; i < page_action_views_.size(); i++) { | 672 for (size_t i = 0; i < page_action_views_.size(); i++) { |
673 page_action_views_[i]->UpdateVisibility( | 673 page_action_views_[i]->UpdateVisibility( |
674 toolbar_model_->input_in_progress() ? NULL : contents, url); | 674 toolbar_model_->input_in_progress() ? NULL : contents, url); |
675 } | 675 } |
676 } | 676 } |
677 | 677 |
678 // If there are no visible page actions, hide the hbox too, so that it does | 678 // If there are no visible page actions, hide the hbox too, so that it does |
679 // not affect the padding in the location bar. | 679 // not affect the padding in the location bar. |
680 gtk_widget_set_visible(page_action_hbox_.get(), | 680 gtk_widget_set_visible(page_action_hbox_.get(), |
681 PageActionVisibleCount() && !ShouldOnlyShowLocation()); | 681 PageActionVisibleCount() && !ShouldOnlyShowLocation()); |
682 } | 682 } |
683 | 683 |
684 void LocationBarViewGtk::InvalidatePageActions() { | 684 void LocationBarViewGtk::InvalidatePageActions() { |
685 size_t count_before = page_action_views_.size(); | 685 size_t count_before = page_action_views_.size(); |
686 page_action_views_.reset(); | 686 page_action_views_.reset(); |
687 if (page_action_views_.size() != count_before) { | 687 if (page_action_views_.size() != count_before) { |
688 NotificationService::current()->Notify( | 688 content::NotificationService::current()->Notify( |
689 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 689 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
690 content::Source<LocationBar>(this), | 690 content::Source<LocationBar>(this), |
691 NotificationService::NoDetails()); | 691 content::NotificationService::NoDetails()); |
692 } | 692 } |
693 } | 693 } |
694 | 694 |
695 void LocationBarViewGtk::SaveStateToContents(TabContents* contents) { | 695 void LocationBarViewGtk::SaveStateToContents(TabContents* contents) { |
696 location_entry_->SaveStateToTab(contents); | 696 location_entry_->SaveStateToTab(contents); |
697 } | 697 } |
698 | 698 |
699 void LocationBarViewGtk::Revert() { | 699 void LocationBarViewGtk::Revert() { |
700 location_entry_->RevertAll(); | 700 location_entry_->RevertAll(); |
701 } | 701 } |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1528 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); | 1528 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); |
1529 } | 1529 } |
1530 | 1530 |
1531 bool old_visible = IsVisible(); | 1531 bool old_visible = IsVisible(); |
1532 if (visible) | 1532 if (visible) |
1533 gtk_widget_show_all(event_box_.get()); | 1533 gtk_widget_show_all(event_box_.get()); |
1534 else | 1534 else |
1535 gtk_widget_hide_all(event_box_.get()); | 1535 gtk_widget_hide_all(event_box_.get()); |
1536 | 1536 |
1537 if (visible != old_visible) { | 1537 if (visible != old_visible) { |
1538 NotificationService::current()->Notify( | 1538 content::NotificationService::current()->Notify( |
1539 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 1539 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
1540 content::Source<ExtensionAction>(page_action_), | 1540 content::Source<ExtensionAction>(page_action_), |
1541 content::Details<TabContents>(contents)); | 1541 content::Details<TabContents>(contents)); |
1542 } | 1542 } |
1543 } | 1543 } |
1544 | 1544 |
1545 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( | 1545 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( |
1546 SkBitmap* image, const ExtensionResource& resource, int index) { | 1546 SkBitmap* image, const ExtensionResource& resource, int index) { |
1547 // We loaded icons()->size() icons, plus one extra if the page action had | 1547 // We loaded icons()->size() icons, plus one extra if the page action had |
1548 // a default icon. | 1548 // a default icon. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 | 1631 |
1632 std::string badge_text = page_action_->GetBadgeText(tab_id); | 1632 std::string badge_text = page_action_->GetBadgeText(tab_id); |
1633 if (badge_text.empty()) | 1633 if (badge_text.empty()) |
1634 return FALSE; | 1634 return FALSE; |
1635 | 1635 |
1636 gfx::CanvasSkiaPaint canvas(event, false); | 1636 gfx::CanvasSkiaPaint canvas(event, false); |
1637 gfx::Rect bounding_rect(widget->allocation); | 1637 gfx::Rect bounding_rect(widget->allocation); |
1638 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); | 1638 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); |
1639 return FALSE; | 1639 return FALSE; |
1640 } | 1640 } |
OLD | NEW |