OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h" | 52 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h" |
53 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" | 53 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
54 #include "chrome/browser/ui/gtk/first_run_bubble.h" | 54 #include "chrome/browser/ui/gtk/first_run_bubble.h" |
55 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 55 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
56 #include "chrome/browser/ui/gtk/gtk_util.h" | 56 #include "chrome/browser/ui/gtk/gtk_util.h" |
57 #include "chrome/browser/ui/gtk/nine_box.h" | 57 #include "chrome/browser/ui/gtk/nine_box.h" |
58 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" | 58 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" |
59 #include "chrome/browser/ui/gtk/rounded_window.h" | 59 #include "chrome/browser/ui/gtk/rounded_window.h" |
60 #include "chrome/browser/ui/gtk/view_id_util.h" | 60 #include "chrome/browser/ui/gtk/view_id_util.h" |
61 #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h" | 61 #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h" |
62 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | |
62 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 63 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
63 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 64 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
64 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 65 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
65 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 66 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
66 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" | 67 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" |
67 #include "chrome/browser/ui/zoom/zoom_controller.h" | 68 #include "chrome/browser/ui/zoom/zoom_controller.h" |
68 #include "chrome/common/chrome_notification_types.h" | 69 #include "chrome/common/chrome_notification_types.h" |
69 #include "chrome/common/extensions/extension.h" | 70 #include "chrome/common/extensions/extension.h" |
70 #include "chrome/common/extensions/extension_action.h" | 71 #include "chrome/common/extensions/extension_action.h" |
71 #include "chrome/common/extensions/extension_manifest_constants.h" | 72 #include "chrome/common/extensions/extension_manifest_constants.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 138 |
138 // Default page tool animation time (open and close). | 139 // Default page tool animation time (open and close). |
139 const int kPageToolAnimationTime = 150; | 140 const int kPageToolAnimationTime = 150; |
140 | 141 |
141 // The time, in ms, that the content setting label is fully displayed, for the | 142 // The time, in ms, that the content setting label is fully displayed, for the |
142 // cases where we animate it into and out of view. | 143 // cases where we animate it into and out of view. |
143 const int kContentSettingImageDisplayTime = 3200; | 144 const int kContentSettingImageDisplayTime = 3200; |
144 // The time, in ms, of the animation (open and close). | 145 // The time, in ms, of the animation (open and close). |
145 const int kContentSettingImageAnimationTime = 150; | 146 const int kContentSettingImageAnimationTime = 150; |
146 | 147 |
148 // Animation opening time for web intents button. | |
149 const int kWebIntentsButtonAnimationTime = 1000; | |
150 | |
147 // Color of border of content setting area (icon/label). | 151 // Color of border of content setting area (icon/label). |
148 const GdkColor kContentSettingBorderColor = GDK_COLOR_RGB(0xe9, 0xb9, 0x66); | 152 const GdkColor kContentSettingBorderColor = GDK_COLOR_RGB(0xe9, 0xb9, 0x66); |
149 // Colors for the background gradient. | 153 // Colors for the background gradient. |
150 const GdkColor kContentSettingTopColor = GDK_COLOR_RGB(0xff, 0xf8, 0xd4); | 154 const GdkColor kContentSettingTopColor = GDK_COLOR_RGB(0xff, 0xf8, 0xd4); |
151 const GdkColor kContentSettingBottomColor = GDK_COLOR_RGB(0xff, 0xe6, 0xaf); | 155 const GdkColor kContentSettingBottomColor = GDK_COLOR_RGB(0xff, 0xe6, 0xaf); |
152 | 156 |
157 // Styling for gray button. | |
158 const GdkColor kGrayBorderColor = GDK_COLOR_RGB(0xa0, 0xa0, 0xa0); | |
159 const GdkColor kTopColorGray = GDK_COLOR_RGB(0xe5, 0xe5, 0xe5); | |
160 const GdkColor kBottomColorGray = GDK_COLOR_RGB(0xd0, 0xd0, 0xd0); | |
161 | |
153 // If widget is visible, increment the int pointed to by count. | 162 // If widget is visible, increment the int pointed to by count. |
154 // Suitible for use with gtk_container_foreach. | 163 // Suitible for use with gtk_container_foreach. |
155 void CountVisibleWidgets(GtkWidget* widget, gpointer count) { | 164 void CountVisibleWidgets(GtkWidget* widget, gpointer count) { |
156 if (gtk_widget_get_visible(widget)) | 165 if (gtk_widget_get_visible(widget)) |
157 *static_cast<int*>(count) += 1; | 166 *static_cast<int*>(count) += 1; |
158 } | 167 } |
159 | 168 |
160 class ContentSettingImageViewGtk : public LocationBarViewGtk::PageToolViewGtk, | 169 class ContentSettingImageViewGtk : public LocationBarViewGtk::PageToolViewGtk, |
161 public BubbleDelegateGtk { | 170 public BubbleDelegateGtk { |
162 public: | 171 public: |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 profile, tab_contents->web_contents()); | 304 profile, tab_contents->web_contents()); |
296 return; | 305 return; |
297 } | 306 } |
298 | 307 |
299 void ContentSettingImageViewGtk::BubbleClosing( | 308 void ContentSettingImageViewGtk::BubbleClosing( |
300 BubbleGtk* bubble, | 309 BubbleGtk* bubble, |
301 bool closed_by_escape) { | 310 bool closed_by_escape) { |
302 content_setting_bubble_ = NULL; | 311 content_setting_bubble_ = NULL; |
303 } | 312 } |
304 | 313 |
314 class WebIntentsButtonViewGtk : public LocationBarViewGtk::PageToolViewGtk { | |
315 public: | |
316 explicit WebIntentsButtonViewGtk(const LocationBarViewGtk* parent) | |
317 : LocationBarViewGtk::PageToolViewGtk(parent) { | |
318 animation_.SetSlideDuration(kWebIntentsButtonAnimationTime); | |
319 } | |
320 virtual ~WebIntentsButtonViewGtk() {} | |
305 | 321 |
322 // PageToolViewGtk | |
323 virtual void Update(TabContents* tab_contents) OVERRIDE; | |
324 | |
325 private: | |
326 // PageToolViewGtk | |
327 virtual GdkColor button_border_color() const OVERRIDE; | |
328 virtual GdkColor gradient_top_color() const OVERRIDE; | |
329 virtual GdkColor gradient_bottom_color() const OVERRIDE; | |
330 virtual void OnClick(GtkWidget* sender) OVERRIDE; | |
331 | |
332 DISALLOW_COPY_AND_ASSIGN(WebIntentsButtonViewGtk); | |
333 }; | |
334 | |
335 void WebIntentsButtonViewGtk::Update( | |
336 TabContents* tab_contents) { | |
337 if (!tab_contents || | |
338 !tab_contents->web_intent_picker_controller() || | |
339 !tab_contents->web_intent_picker_controller()-> | |
340 ShowLocationBarPickerTool()) { | |
341 gtk_widget_hide(widget()); | |
342 return; | |
343 } | |
344 | |
345 gtk_widget_set_tooltip_text(widget(), | |
346 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str()); | |
347 gtk_widget_show_all(widget()); | |
348 | |
349 gtk_label_set_text(GTK_LABEL(label_.get()), | |
350 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str()); | |
351 | |
352 StartAnimating(); | |
353 } | |
354 | |
355 void WebIntentsButtonViewGtk::OnClick(GtkWidget* sender) { | |
356 LOG(INFO) << "Web Intents button click"; | |
Bernhard Bauer
2012/07/31 23:29:15
Nit: Could you make this a DLOG? That way we don't
Greg Billock
2012/08/07 01:12:40
Done.
| |
357 } | |
358 | |
359 GdkColor WebIntentsButtonViewGtk::button_border_color() const { | |
360 return kGrayBorderColor; | |
361 } | |
362 | |
363 GdkColor WebIntentsButtonViewGtk::gradient_top_color() const { | |
364 return kTopColorGray; | |
365 } | |
366 | |
367 GdkColor WebIntentsButtonViewGtk::gradient_bottom_color() const { | |
368 return kBottomColorGray; | |
369 } | |
306 | 370 |
307 } // namespace | 371 } // namespace |
308 | 372 |
309 //////////////////////////////////////////////////////////////////////////////// | 373 //////////////////////////////////////////////////////////////////////////////// |
310 // LocationBarViewGtk | 374 // LocationBarViewGtk |
311 | 375 |
312 // static | 376 // static |
313 const GdkColor LocationBarViewGtk::kBackgroundColor = | 377 const GdkColor LocationBarViewGtk::kBackgroundColor = |
314 GDK_COLOR_RGB(255, 255, 255); | 378 GDK_COLOR_RGB(255, 255, 255); |
315 | 379 |
316 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) | 380 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) |
317 : zoom_image_(NULL), | 381 : zoom_image_(NULL), |
318 star_image_(NULL), | 382 star_image_(NULL), |
319 starred_(false), | 383 starred_(false), |
320 chrome_to_mobile_image_(NULL), | 384 chrome_to_mobile_image_(NULL), |
321 site_type_alignment_(NULL), | 385 site_type_alignment_(NULL), |
322 site_type_event_box_(NULL), | 386 site_type_event_box_(NULL), |
323 location_icon_image_(NULL), | 387 location_icon_image_(NULL), |
324 drag_icon_(NULL), | 388 drag_icon_(NULL), |
325 enable_location_drag_(false), | 389 enable_location_drag_(false), |
326 security_info_label_(NULL), | 390 security_info_label_(NULL), |
391 web_intents_button_view_(new WebIntentsButtonViewGtk(this)), | |
327 tab_to_search_alignment_(NULL), | 392 tab_to_search_alignment_(NULL), |
328 tab_to_search_box_(NULL), | 393 tab_to_search_box_(NULL), |
329 tab_to_search_full_label_(NULL), | 394 tab_to_search_full_label_(NULL), |
330 tab_to_search_partial_label_(NULL), | 395 tab_to_search_partial_label_(NULL), |
331 tab_to_search_hint_(NULL), | 396 tab_to_search_hint_(NULL), |
332 tab_to_search_hint_leading_label_(NULL), | 397 tab_to_search_hint_leading_label_(NULL), |
333 tab_to_search_hint_icon_(NULL), | 398 tab_to_search_hint_icon_(NULL), |
334 tab_to_search_hint_trailing_label_(NULL), | 399 tab_to_search_hint_trailing_label_(NULL), |
335 command_updater_(browser->command_controller()->command_updater()), | 400 command_updater_(browser->command_controller()->command_updater()), |
336 toolbar_model_(browser->toolbar_model()), | 401 toolbar_model_(browser->toolbar_model()), |
(...skipping 12 matching lines...) Expand all Loading... | |
349 } | 414 } |
350 | 415 |
351 LocationBarViewGtk::~LocationBarViewGtk() { | 416 LocationBarViewGtk::~LocationBarViewGtk() { |
352 // All of our widgets should be children of / owned by the alignment. | 417 // All of our widgets should be children of / owned by the alignment. |
353 zoom_.Destroy(); | 418 zoom_.Destroy(); |
354 star_.Destroy(); | 419 star_.Destroy(); |
355 chrome_to_mobile_view_.Destroy(); | 420 chrome_to_mobile_view_.Destroy(); |
356 hbox_.Destroy(); | 421 hbox_.Destroy(); |
357 content_setting_hbox_.Destroy(); | 422 content_setting_hbox_.Destroy(); |
358 page_action_hbox_.Destroy(); | 423 page_action_hbox_.Destroy(); |
424 web_intents_hbox_.Destroy(); | |
359 } | 425 } |
360 | 426 |
361 void LocationBarViewGtk::Init(bool popup_window_mode) { | 427 void LocationBarViewGtk::Init(bool popup_window_mode) { |
362 popup_window_mode_ = popup_window_mode; | 428 popup_window_mode_ = popup_window_mode; |
363 | 429 |
364 Profile* profile = browser_->profile(); | 430 Profile* profile = browser_->profile(); |
365 theme_service_ = GtkThemeService::GetFrom(profile); | 431 theme_service_ = GtkThemeService::GetFrom(profile); |
366 | 432 |
367 // Create the widget first, so we can pass it to the OmniboxViewGtk. | 433 // Create the widget first, so we can pass it to the OmniboxViewGtk. |
368 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); | 434 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()), | 570 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()), |
505 content_setting_view->widget(), FALSE, FALSE, 0); | 571 content_setting_view->widget(), FALSE, FALSE, 0); |
506 } | 572 } |
507 | 573 |
508 page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); | 574 page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); |
509 gtk_widget_set_name(page_action_hbox_.get(), | 575 gtk_widget_set_name(page_action_hbox_.get(), |
510 "chrome-page-action-hbox"); | 576 "chrome-page-action-hbox"); |
511 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), | 577 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), |
512 FALSE, FALSE, 0); | 578 FALSE, FALSE, 0); |
513 | 579 |
580 web_intents_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); | |
581 gtk_widget_set_name(web_intents_hbox_.get(), | |
582 "chrome-web-intents-hbox"); | |
583 gtk_box_pack_end(GTK_BOX(hbox_.get()), web_intents_hbox_.get(), | |
584 FALSE, FALSE, 0); | |
585 gtk_box_pack_end(GTK_BOX(web_intents_hbox_.get()), | |
586 web_intents_button_view_->widget(), FALSE, FALSE, 0); | |
587 | |
514 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s | 588 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s |
515 // size-allocate so we can do proper resizing and eliding on | 589 // size-allocate so we can do proper resizing and eliding on |
516 // |security_info_label_|. | 590 // |security_info_label_|. |
517 g_signal_connect(hbox_.get(), "size-allocate", | 591 g_signal_connect(hbox_.get(), "size-allocate", |
518 G_CALLBACK(&OnHboxSizeAllocateThunk), this); | 592 G_CALLBACK(&OnHboxSizeAllocateThunk), this); |
519 | 593 |
520 registrar_.Add(this, | 594 registrar_.Add(this, |
521 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 595 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
522 content::Source<ThemeService>(theme_service_)); | 596 content::Source<ThemeService>(theme_service_)); |
523 registrar_.Add(this, | 597 registrar_.Add(this, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 return NULL; | 709 return NULL; |
636 } | 710 } |
637 | 711 |
638 void LocationBarViewGtk::Update(const WebContents* contents) { | 712 void LocationBarViewGtk::Update(const WebContents* contents) { |
639 UpdateZoomIcon(); | 713 UpdateZoomIcon(); |
640 UpdateStarIcon(); | 714 UpdateStarIcon(); |
641 UpdateChromeToMobileIcon(); | 715 UpdateChromeToMobileIcon(); |
642 UpdateSiteTypeArea(); | 716 UpdateSiteTypeArea(); |
643 UpdateContentSettingsIcons(); | 717 UpdateContentSettingsIcons(); |
644 UpdatePageActions(); | 718 UpdatePageActions(); |
719 UpdateWebIntentsTool(); | |
645 location_entry_->Update(contents); | 720 location_entry_->Update(contents); |
646 // The security level (background color) could have changed, etc. | 721 // The security level (background color) could have changed, etc. |
647 if (theme_service_->UsingNativeTheme()) { | 722 if (theme_service_->UsingNativeTheme()) { |
648 // In GTK mode, we need our parent to redraw, as it draws the text entry | 723 // In GTK mode, we need our parent to redraw, as it draws the text entry |
649 // border. | 724 // border. |
650 gtk_widget_queue_draw(gtk_widget_get_parent(widget())); | 725 gtk_widget_queue_draw(gtk_widget_get_parent(widget())); |
651 } else { | 726 } else { |
652 gtk_widget_queue_draw(widget()); | 727 gtk_widget_queue_draw(widget()); |
653 } | 728 } |
654 } | 729 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 size_t count_before = page_action_views_.size(); | 992 size_t count_before = page_action_views_.size(); |
918 page_action_views_.clear(); | 993 page_action_views_.clear(); |
919 if (page_action_views_.size() != count_before) { | 994 if (page_action_views_.size() != count_before) { |
920 content::NotificationService::current()->Notify( | 995 content::NotificationService::current()->Notify( |
921 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 996 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
922 content::Source<LocationBar>(this), | 997 content::Source<LocationBar>(this), |
923 content::NotificationService::NoDetails()); | 998 content::NotificationService::NoDetails()); |
924 } | 999 } |
925 } | 1000 } |
926 | 1001 |
1002 void LocationBarViewGtk::UpdateWebIntentsTool() { | |
1003 web_intents_button_view_->Update(GetTabContents()); | |
1004 gtk_widget_set_visible(web_intents_hbox_.get(), | |
1005 web_intents_button_view_->IsVisible()); | |
1006 } | |
1007 | |
927 void LocationBarViewGtk::SaveStateToContents(WebContents* contents) { | 1008 void LocationBarViewGtk::SaveStateToContents(WebContents* contents) { |
928 location_entry_->SaveStateToTab(contents); | 1009 location_entry_->SaveStateToTab(contents); |
929 } | 1010 } |
930 | 1011 |
931 void LocationBarViewGtk::Revert() { | 1012 void LocationBarViewGtk::Revert() { |
932 location_entry_->RevertAll(); | 1013 location_entry_->RevertAll(); |
933 } | 1014 } |
934 | 1015 |
935 const OmniboxView* LocationBarViewGtk::GetLocationEntry() const { | 1016 const OmniboxView* LocationBarViewGtk::GetLocationEntry() const { |
936 return location_entry_.get(); | 1017 return location_entry_.get(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1059 1, 1, 0, 0); | 1140 1, 1, 0, 0); |
1060 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), | 1141 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), |
1061 1, 1, 0, 0); | 1142 1, 1, 0, 0); |
1062 } | 1143 } |
1063 | 1144 |
1064 UpdateZoomIcon(); | 1145 UpdateZoomIcon(); |
1065 UpdateStarIcon(); | 1146 UpdateStarIcon(); |
1066 UpdateChromeToMobileIcon(); | 1147 UpdateChromeToMobileIcon(); |
1067 UpdateSiteTypeArea(); | 1148 UpdateSiteTypeArea(); |
1068 UpdateContentSettingsIcons(); | 1149 UpdateContentSettingsIcons(); |
1150 UpdateWebIntentsTool(); | |
1069 break; | 1151 break; |
1070 } | 1152 } |
1071 | 1153 |
1072 default: | 1154 default: |
1073 NOTREACHED(); | 1155 NOTREACHED(); |
1074 } | 1156 } |
1075 } | 1157 } |
1076 | 1158 |
1077 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, | 1159 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, |
1078 GdkEventExpose* event) { | 1160 GdkEventExpose* event) { |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2050 } | 2132 } |
2051 | 2133 |
2052 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( | 2134 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
2053 ExtensionAction* action) { | 2135 ExtensionAction* action) { |
2054 ExtensionPopupGtk::Show( | 2136 ExtensionPopupGtk::Show( |
2055 action->GetPopupUrl(current_tab_id_), | 2137 action->GetPopupUrl(current_tab_id_), |
2056 owner_->browser_, | 2138 owner_->browser_, |
2057 event_box_.get(), | 2139 event_box_.get(), |
2058 ExtensionPopupGtk::SHOW_AND_INSPECT); | 2140 ExtensionPopupGtk::SHOW_AND_INSPECT); |
2059 } | 2141 } |
OLD | NEW |