| 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 29 matching lines...) Expand all Loading... |
| 40 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" | 40 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
| 41 #include "chrome/browser/ui/gtk/first_run_bubble.h" | 41 #include "chrome/browser/ui/gtk/first_run_bubble.h" |
| 42 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 42 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 43 #include "chrome/browser/ui/gtk/gtk_util.h" | 43 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 44 #include "chrome/browser/ui/gtk/nine_box.h" | 44 #include "chrome/browser/ui/gtk/nine_box.h" |
| 45 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" | 45 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" |
| 46 #include "chrome/browser/ui/gtk/rounded_window.h" | 46 #include "chrome/browser/ui/gtk/rounded_window.h" |
| 47 #include "chrome/browser/ui/gtk/view_id_util.h" | 47 #include "chrome/browser/ui/gtk/view_id_util.h" |
| 48 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 48 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
| 49 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 49 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 50 #include "chrome/common/chrome_notification_types.h" |
| 50 #include "chrome/common/extensions/extension.h" | 51 #include "chrome/common/extensions/extension.h" |
| 51 #include "chrome/common/extensions/extension_action.h" | 52 #include "chrome/common/extensions/extension_action.h" |
| 52 #include "chrome/common/extensions/extension_resource.h" | 53 #include "chrome/common/extensions/extension_resource.h" |
| 53 #include "chrome/common/pref_names.h" | 54 #include "chrome/common/pref_names.h" |
| 54 #include "content/browser/tab_contents/tab_contents.h" | 55 #include "content/browser/tab_contents/tab_contents.h" |
| 55 #include "content/common/notification_service.h" | 56 #include "content/common/notification_service.h" |
| 56 #include "content/common/page_transition_types.h" | 57 #include "content/common/page_transition_types.h" |
| 57 #include "grit/generated_resources.h" | 58 #include "grit/generated_resources.h" |
| 58 #include "grit/theme_resources.h" | 59 #include "grit/theme_resources.h" |
| 59 #include "grit/theme_resources_standard.h" | 60 #include "grit/theme_resources_standard.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), | 325 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), |
| 325 FALSE, FALSE, 0); | 326 FALSE, FALSE, 0); |
| 326 | 327 |
| 327 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s | 328 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s |
| 328 // size-allocate so we can do proper resizing and eliding on | 329 // size-allocate so we can do proper resizing and eliding on |
| 329 // |security_info_label_|. | 330 // |security_info_label_|. |
| 330 g_signal_connect(hbox_.get(), "size-allocate", | 331 g_signal_connect(hbox_.get(), "size-allocate", |
| 331 G_CALLBACK(&OnHboxSizeAllocateThunk), this); | 332 G_CALLBACK(&OnHboxSizeAllocateThunk), this); |
| 332 | 333 |
| 333 registrar_.Add(this, | 334 registrar_.Add(this, |
| 334 NotificationType::BROWSER_THEME_CHANGED, | 335 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 335 NotificationService::AllSources()); | 336 NotificationService::AllSources()); |
| 336 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, | 337 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, |
| 337 profile_->GetPrefs(), this); | 338 profile_->GetPrefs(), this); |
| 338 | 339 |
| 339 theme_service_->InitThemesFor(this); | 340 theme_service_->InitThemesFor(this); |
| 340 } | 341 } |
| 341 | 342 |
| 342 void LocationBarViewGtk::BuildSiteTypeArea() { | 343 void LocationBarViewGtk::BuildSiteTypeArea() { |
| 343 location_icon_image_ = gtk_image_new(); | 344 location_icon_image_ = gtk_image_new(); |
| 344 gtk_widget_set_name(location_icon_image_, "chrome-location-icon"); | 345 gtk_widget_set_name(location_icon_image_, "chrome-location-icon"); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 552 |
| 552 void LocationBarViewGtk::OnKillFocus() { | 553 void LocationBarViewGtk::OnKillFocus() { |
| 553 } | 554 } |
| 554 | 555 |
| 555 void LocationBarViewGtk::OnSetFocus() { | 556 void LocationBarViewGtk::OnSetFocus() { |
| 556 AccessibilityTextBoxInfo info( | 557 AccessibilityTextBoxInfo info( |
| 557 profile_, | 558 profile_, |
| 558 l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION).c_str(), | 559 l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION).c_str(), |
| 559 false); | 560 false); |
| 560 NotificationService::current()->Notify( | 561 NotificationService::current()->Notify( |
| 561 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, | 562 chrome::NOTIFICATION_ACCESSIBILITY_CONTROL_FOCUSED, |
| 562 Source<Profile>(profile_), | 563 Source<Profile>(profile_), |
| 563 Details<AccessibilityTextBoxInfo>(&info)); | 564 Details<AccessibilityTextBoxInfo>(&info)); |
| 564 | 565 |
| 565 // Update the keyword and search hint states. | 566 // Update the keyword and search hint states. |
| 566 OnChanged(); | 567 OnChanged(); |
| 567 } | 568 } |
| 568 | 569 |
| 569 SkBitmap LocationBarViewGtk::GetFavicon() const { | 570 SkBitmap LocationBarViewGtk::GetFavicon() const { |
| 570 return GetTabContentsWrapper()->favicon_tab_helper()->GetFavicon(); | 571 return GetTabContentsWrapper()->favicon_tab_helper()->GetFavicon(); |
| 571 } | 572 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 if (page_actions.size() != page_action_views_.size()) { | 656 if (page_actions.size() != page_action_views_.size()) { |
| 656 page_action_views_.reset(); // Delete the old views (if any). | 657 page_action_views_.reset(); // Delete the old views (if any). |
| 657 | 658 |
| 658 for (size_t i = 0; i < page_actions.size(); ++i) { | 659 for (size_t i = 0; i < page_actions.size(); ++i) { |
| 659 page_action_views_.push_back( | 660 page_action_views_.push_back( |
| 660 new PageActionViewGtk(this, profile_, page_actions[i])); | 661 new PageActionViewGtk(this, profile_, page_actions[i])); |
| 661 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), | 662 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), |
| 662 page_action_views_[i]->widget(), FALSE, FALSE, 0); | 663 page_action_views_[i]->widget(), FALSE, FALSE, 0); |
| 663 } | 664 } |
| 664 NotificationService::current()->Notify( | 665 NotificationService::current()->Notify( |
| 665 NotificationType::EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 666 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
| 666 Source<LocationBar>(this), | 667 Source<LocationBar>(this), |
| 667 NotificationService::NoDetails()); | 668 NotificationService::NoDetails()); |
| 668 } | 669 } |
| 669 | 670 |
| 670 TabContents* contents = GetTabContents(); | 671 TabContents* contents = GetTabContents(); |
| 671 if (!page_action_views_.empty() && contents) { | 672 if (!page_action_views_.empty() && contents) { |
| 672 GURL url = GURL(WideToUTF8(toolbar_model_->GetText())); | 673 GURL url = GURL(WideToUTF8(toolbar_model_->GetText())); |
| 673 | 674 |
| 674 for (size_t i = 0; i < page_action_views_.size(); i++) { | 675 for (size_t i = 0; i < page_action_views_.size(); i++) { |
| 675 page_action_views_[i]->UpdateVisibility( | 676 page_action_views_[i]->UpdateVisibility( |
| 676 toolbar_model_->input_in_progress() ? NULL : contents, url); | 677 toolbar_model_->input_in_progress() ? NULL : contents, url); |
| 677 } | 678 } |
| 678 } | 679 } |
| 679 | 680 |
| 680 // If there are no visible page actions, hide the hbox too, so that it does | 681 // If there are no visible page actions, hide the hbox too, so that it does |
| 681 // not affect the padding in the location bar. | 682 // not affect the padding in the location bar. |
| 682 gtk_widget_set_visible(page_action_hbox_.get(), | 683 gtk_widget_set_visible(page_action_hbox_.get(), |
| 683 PageActionVisibleCount() && !ShouldOnlyShowLocation()); | 684 PageActionVisibleCount() && !ShouldOnlyShowLocation()); |
| 684 } | 685 } |
| 685 | 686 |
| 686 void LocationBarViewGtk::InvalidatePageActions() { | 687 void LocationBarViewGtk::InvalidatePageActions() { |
| 687 size_t count_before = page_action_views_.size(); | 688 size_t count_before = page_action_views_.size(); |
| 688 page_action_views_.reset(); | 689 page_action_views_.reset(); |
| 689 if (page_action_views_.size() != count_before) { | 690 if (page_action_views_.size() != count_before) { |
| 690 NotificationService::current()->Notify( | 691 NotificationService::current()->Notify( |
| 691 NotificationType::EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 692 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
| 692 Source<LocationBar>(this), | 693 Source<LocationBar>(this), |
| 693 NotificationService::NoDetails()); | 694 NotificationService::NoDetails()); |
| 694 } | 695 } |
| 695 } | 696 } |
| 696 | 697 |
| 697 void LocationBarViewGtk::SaveStateToContents(TabContents* contents) { | 698 void LocationBarViewGtk::SaveStateToContents(TabContents* contents) { |
| 698 location_entry_->SaveStateToTab(contents); | 699 location_entry_->SaveStateToTab(contents); |
| 699 } | 700 } |
| 700 | 701 |
| 701 void LocationBarViewGtk::Revert() { | 702 void LocationBarViewGtk::Revert() { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 | 750 |
| 750 void LocationBarViewGtk::TestPageActionPressed(size_t index) { | 751 void LocationBarViewGtk::TestPageActionPressed(size_t index) { |
| 751 if (index >= page_action_views_.size()) { | 752 if (index >= page_action_views_.size()) { |
| 752 NOTREACHED(); | 753 NOTREACHED(); |
| 753 return; | 754 return; |
| 754 } | 755 } |
| 755 | 756 |
| 756 page_action_views_[index]->TestActivatePageAction(); | 757 page_action_views_[index]->TestActivatePageAction(); |
| 757 } | 758 } |
| 758 | 759 |
| 759 void LocationBarViewGtk::Observe(NotificationType type, | 760 void LocationBarViewGtk::Observe(int type, |
| 760 const NotificationSource& source, | 761 const NotificationSource& source, |
| 761 const NotificationDetails& details) { | 762 const NotificationDetails& details) { |
| 762 if (type.value == NotificationType::PREF_CHANGED) { | 763 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 763 UpdateStarIcon(); | 764 UpdateStarIcon(); |
| 764 return; | 765 return; |
| 765 } | 766 } |
| 766 | 767 |
| 767 DCHECK_EQ(type.value, NotificationType::BROWSER_THEME_CHANGED); | 768 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_THEME_CHANGED); |
| 768 | 769 |
| 769 if (theme_service_->UsingNativeTheme()) { | 770 if (theme_service_->UsingNativeTheme()) { |
| 770 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); | 771 gtk_widget_modify_bg(tab_to_search_box_, GTK_STATE_NORMAL, NULL); |
| 771 | 772 |
| 772 GdkColor border_color = theme_service_->GetGdkColor( | 773 GdkColor border_color = theme_service_->GetGdkColor( |
| 773 ThemeService::COLOR_FRAME); | 774 ThemeService::COLOR_FRAME); |
| 774 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); | 775 gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_, border_color); |
| 775 | 776 |
| 776 gtk_util::UndoForceFontSize(security_info_label_); | 777 gtk_util::UndoForceFontSize(security_info_label_); |
| 777 gtk_util::UndoForceFontSize(tab_to_search_full_label_); | 778 gtk_util::UndoForceFontSize(tab_to_search_full_label_); |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 } | 1517 } |
| 1517 | 1518 |
| 1518 bool old_visible = IsVisible(); | 1519 bool old_visible = IsVisible(); |
| 1519 if (visible) | 1520 if (visible) |
| 1520 gtk_widget_show_all(event_box_.get()); | 1521 gtk_widget_show_all(event_box_.get()); |
| 1521 else | 1522 else |
| 1522 gtk_widget_hide_all(event_box_.get()); | 1523 gtk_widget_hide_all(event_box_.get()); |
| 1523 | 1524 |
| 1524 if (visible != old_visible) { | 1525 if (visible != old_visible) { |
| 1525 NotificationService::current()->Notify( | 1526 NotificationService::current()->Notify( |
| 1526 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 1527 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| 1527 Source<ExtensionAction>(page_action_), | 1528 Source<ExtensionAction>(page_action_), |
| 1528 Details<TabContents>(contents)); | 1529 Details<TabContents>(contents)); |
| 1529 } | 1530 } |
| 1530 } | 1531 } |
| 1531 | 1532 |
| 1532 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( | 1533 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( |
| 1533 SkBitmap* image, const ExtensionResource& resource, int index) { | 1534 SkBitmap* image, const ExtensionResource& resource, int index) { |
| 1534 // We loaded icons()->size() icons, plus one extra if the page action had | 1535 // We loaded icons()->size() icons, plus one extra if the page action had |
| 1535 // a default icon. | 1536 // a default icon. |
| 1536 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); | 1537 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 | 1621 |
| 1621 std::string badge_text = page_action_->GetBadgeText(tab_id); | 1622 std::string badge_text = page_action_->GetBadgeText(tab_id); |
| 1622 if (badge_text.empty()) | 1623 if (badge_text.empty()) |
| 1623 return FALSE; | 1624 return FALSE; |
| 1624 | 1625 |
| 1625 gfx::CanvasSkiaPaint canvas(event, false); | 1626 gfx::CanvasSkiaPaint canvas(event, false); |
| 1626 gfx::Rect bounding_rect(widget->allocation); | 1627 gfx::Rect bounding_rect(widget->allocation); |
| 1627 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); | 1628 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); |
| 1628 return FALSE; | 1629 return FALSE; |
| 1629 } | 1630 } |
| OLD | NEW |