OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" | 54 #include "chrome/browser/ui/gtk/extensions/extension_popup_gtk.h" |
55 #include "chrome/browser/ui/gtk/first_run_bubble.h" | 55 #include "chrome/browser/ui/gtk/first_run_bubble.h" |
56 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 56 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
57 #include "chrome/browser/ui/gtk/gtk_util.h" | 57 #include "chrome/browser/ui/gtk/gtk_util.h" |
58 #include "chrome/browser/ui/gtk/nine_box.h" | 58 #include "chrome/browser/ui/gtk/nine_box.h" |
59 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" | 59 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" |
60 #include "chrome/browser/ui/gtk/rounded_window.h" | 60 #include "chrome/browser/ui/gtk/rounded_window.h" |
61 #include "chrome/browser/ui/gtk/script_bubble_gtk.h" | 61 #include "chrome/browser/ui/gtk/script_bubble_gtk.h" |
62 #include "chrome/browser/ui/gtk/view_id_util.h" | 62 #include "chrome/browser/ui/gtk/view_id_util.h" |
63 #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h" | 63 #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h" |
64 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" | |
65 #include "chrome/browser/ui/omnibox/alternate_nav_url_fetcher.h" | 64 #include "chrome/browser/ui/omnibox/alternate_nav_url_fetcher.h" |
66 #include "chrome/browser/ui/omnibox/location_bar_util.h" | 65 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
67 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 66 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
68 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 67 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
69 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 68 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
70 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" | 69 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" |
71 #include "chrome/browser/ui/zoom/zoom_controller.h" | 70 #include "chrome/browser/ui/zoom/zoom_controller.h" |
72 #include "chrome/common/badge_util.h" | 71 #include "chrome/common/badge_util.h" |
73 #include "chrome/common/chrome_notification_types.h" | 72 #include "chrome/common/chrome_notification_types.h" |
74 #include "chrome/common/chrome_switches.h" | 73 #include "chrome/common/chrome_switches.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 140 |
142 // Default page tool animation time (open and close). In ms. | 141 // Default page tool animation time (open and close). In ms. |
143 const int kPageToolAnimationTime = 150; | 142 const int kPageToolAnimationTime = 150; |
144 | 143 |
145 // The time, in ms, that the content setting label is fully displayed, for the | 144 // The time, in ms, that the content setting label is fully displayed, for the |
146 // cases where we animate it into and out of view. | 145 // cases where we animate it into and out of view. |
147 const int kContentSettingImageDisplayTime = 3200; | 146 const int kContentSettingImageDisplayTime = 3200; |
148 // The time, in ms, of the animation (open and close). | 147 // The time, in ms, of the animation (open and close). |
149 const int kContentSettingImageAnimationTime = 150; | 148 const int kContentSettingImageAnimationTime = 150; |
150 | 149 |
151 #if defined(ENABLE_WEB_INTENTS) | |
152 // Animation opening time for web intents button (in ms). | |
153 const int kWebIntentsButtonAnimationTime = 150; | |
154 #endif | |
155 | |
156 // Color of border of content setting area (icon/label). | 150 // Color of border of content setting area (icon/label). |
157 const GdkColor kContentSettingBorderColor = GDK_COLOR_RGB(0xe9, 0xb9, 0x66); | 151 const GdkColor kContentSettingBorderColor = GDK_COLOR_RGB(0xe9, 0xb9, 0x66); |
158 // Colors for the background gradient. | 152 // Colors for the background gradient. |
159 const GdkColor kContentSettingTopColor = GDK_COLOR_RGB(0xff, 0xf8, 0xd4); | 153 const GdkColor kContentSettingTopColor = GDK_COLOR_RGB(0xff, 0xf8, 0xd4); |
160 const GdkColor kContentSettingBottomColor = GDK_COLOR_RGB(0xff, 0xe6, 0xaf); | 154 const GdkColor kContentSettingBottomColor = GDK_COLOR_RGB(0xff, 0xe6, 0xaf); |
161 | 155 |
162 // Styling for gray button. | 156 // Styling for gray button. |
163 const GdkColor kGrayBorderColor = GDK_COLOR_RGB(0xa0, 0xa0, 0xa0); | 157 const GdkColor kGrayBorderColor = GDK_COLOR_RGB(0xa0, 0xa0, 0xa0); |
164 const GdkColor kTopColorGray = GDK_COLOR_RGB(0xe5, 0xe5, 0xe5); | 158 const GdkColor kTopColorGray = GDK_COLOR_RGB(0xe5, 0xe5, 0xe5); |
165 const GdkColor kBottomColorGray = GDK_COLOR_RGB(0xd0, 0xd0, 0xd0); | 159 const GdkColor kBottomColorGray = GDK_COLOR_RGB(0xd0, 0xd0, 0xd0); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 profile, web_contents); | 306 profile, web_contents); |
313 return; | 307 return; |
314 } | 308 } |
315 | 309 |
316 void ContentSettingImageViewGtk::BubbleClosing( | 310 void ContentSettingImageViewGtk::BubbleClosing( |
317 BubbleGtk* bubble, | 311 BubbleGtk* bubble, |
318 bool closed_by_escape) { | 312 bool closed_by_escape) { |
319 content_setting_bubble_ = NULL; | 313 content_setting_bubble_ = NULL; |
320 } | 314 } |
321 | 315 |
322 #if defined(ENABLE_WEB_INTENTS) | |
323 class WebIntentsButtonViewGtk : public LocationBarViewGtk::PageToolViewGtk { | |
324 public: | |
325 explicit WebIntentsButtonViewGtk(const LocationBarViewGtk* parent) | |
326 : LocationBarViewGtk::PageToolViewGtk(parent) { | |
327 animation_.SetSlideDuration(kWebIntentsButtonAnimationTime); | |
328 } | |
329 virtual ~WebIntentsButtonViewGtk() {} | |
330 | |
331 // PageToolViewGtk | |
332 virtual void Update(WebContents* web_contents) OVERRIDE; | |
333 | |
334 private: | |
335 // PageToolViewGtk | |
336 virtual GdkColor button_border_color() const OVERRIDE; | |
337 virtual GdkColor gradient_top_color() const OVERRIDE; | |
338 virtual GdkColor gradient_bottom_color() const OVERRIDE; | |
339 virtual void OnClick(GtkWidget* sender) OVERRIDE; | |
340 | |
341 DISALLOW_COPY_AND_ASSIGN(WebIntentsButtonViewGtk); | |
342 }; | |
343 | |
344 void WebIntentsButtonViewGtk::Update(WebContents* web_contents) { | |
345 WebIntentPickerController* web_intent_picker_controller = | |
346 web_contents ? WebIntentPickerController::FromWebContents(web_contents) | |
347 : NULL; | |
348 if (!web_intent_picker_controller || | |
349 !web_intent_picker_controller->ShowLocationBarPickerButton()) { | |
350 gtk_widget_hide(widget()); | |
351 return; | |
352 } | |
353 | |
354 gtk_widget_set_tooltip_text(widget(), | |
355 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str()); | |
356 gtk_widget_show_all(widget()); | |
357 | |
358 gtk_label_set_text(GTK_LABEL(label_.get()), | |
359 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str()); | |
360 | |
361 StartAnimating(); | |
362 } | |
363 | |
364 void WebIntentsButtonViewGtk::OnClick(GtkWidget* sender) { | |
365 WebContents* web_contents = parent_->GetWebContents(); | |
366 if (!web_contents) | |
367 return; | |
368 | |
369 WebIntentPickerController::FromWebContents(web_contents)-> | |
370 LocationBarPickerButtonClicked(); | |
371 } | |
372 | |
373 GdkColor WebIntentsButtonViewGtk::button_border_color() const { | |
374 return kGrayBorderColor; | |
375 } | |
376 | |
377 GdkColor WebIntentsButtonViewGtk::gradient_top_color() const { | |
378 return kTopColorGray; | |
379 } | |
380 | |
381 GdkColor WebIntentsButtonViewGtk::gradient_bottom_color() const { | |
382 return kBottomColorGray; | |
383 } | |
384 #endif | |
385 | |
386 } // namespace | 316 } // namespace |
387 | 317 |
388 //////////////////////////////////////////////////////////////////////////////// | 318 //////////////////////////////////////////////////////////////////////////////// |
389 // LocationBarViewGtk | 319 // LocationBarViewGtk |
390 | 320 |
391 // static | 321 // static |
392 const GdkColor LocationBarViewGtk::kBackgroundColor = | 322 const GdkColor LocationBarViewGtk::kBackgroundColor = |
393 GDK_COLOR_RGB(255, 255, 255); | 323 GDK_COLOR_RGB(255, 255, 255); |
394 | 324 |
395 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) | 325 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) |
396 : zoom_image_(NULL), | 326 : zoom_image_(NULL), |
397 script_bubble_button_image_(NULL), | 327 script_bubble_button_image_(NULL), |
398 num_running_scripts_(0u), | 328 num_running_scripts_(0u), |
399 star_image_(NULL), | 329 star_image_(NULL), |
400 starred_(false), | 330 starred_(false), |
401 star_sized_(false), | 331 star_sized_(false), |
402 site_type_alignment_(NULL), | 332 site_type_alignment_(NULL), |
403 site_type_event_box_(NULL), | 333 site_type_event_box_(NULL), |
404 location_icon_image_(NULL), | 334 location_icon_image_(NULL), |
405 drag_icon_(NULL), | 335 drag_icon_(NULL), |
406 enable_location_drag_(false), | 336 enable_location_drag_(false), |
407 security_info_label_(NULL), | 337 security_info_label_(NULL), |
408 #if defined(ENABLE_WEB_INTENTS) | |
409 web_intents_button_view_(new WebIntentsButtonViewGtk(this)), | |
410 #endif | |
411 tab_to_search_alignment_(NULL), | 338 tab_to_search_alignment_(NULL), |
412 tab_to_search_box_(NULL), | 339 tab_to_search_box_(NULL), |
413 tab_to_search_full_label_(NULL), | 340 tab_to_search_full_label_(NULL), |
414 tab_to_search_partial_label_(NULL), | 341 tab_to_search_partial_label_(NULL), |
415 tab_to_search_hint_(NULL), | 342 tab_to_search_hint_(NULL), |
416 tab_to_search_hint_leading_label_(NULL), | 343 tab_to_search_hint_leading_label_(NULL), |
417 tab_to_search_hint_icon_(NULL), | 344 tab_to_search_hint_icon_(NULL), |
418 tab_to_search_hint_trailing_label_(NULL), | 345 tab_to_search_hint_trailing_label_(NULL), |
419 command_updater_(browser->command_controller()->command_updater()), | 346 command_updater_(browser->command_controller()->command_updater()), |
420 toolbar_model_(browser->toolbar_model()), | 347 toolbar_model_(browser->toolbar_model()), |
(...skipping 12 matching lines...) Expand all Loading... |
433 } | 360 } |
434 | 361 |
435 LocationBarViewGtk::~LocationBarViewGtk() { | 362 LocationBarViewGtk::~LocationBarViewGtk() { |
436 // All of our widgets should be children of / owned by the alignment. | 363 // All of our widgets should be children of / owned by the alignment. |
437 zoom_.Destroy(); | 364 zoom_.Destroy(); |
438 script_bubble_button_.Destroy(); | 365 script_bubble_button_.Destroy(); |
439 star_.Destroy(); | 366 star_.Destroy(); |
440 hbox_.Destroy(); | 367 hbox_.Destroy(); |
441 content_setting_hbox_.Destroy(); | 368 content_setting_hbox_.Destroy(); |
442 page_action_hbox_.Destroy(); | 369 page_action_hbox_.Destroy(); |
443 #if defined(ENABLE_WEB_INTENTS) | |
444 web_intents_hbox_.Destroy(); | |
445 #endif | |
446 } | 370 } |
447 | 371 |
448 void LocationBarViewGtk::Init(bool popup_window_mode) { | 372 void LocationBarViewGtk::Init(bool popup_window_mode) { |
449 popup_window_mode_ = popup_window_mode; | 373 popup_window_mode_ = popup_window_mode; |
450 | 374 |
451 Profile* profile = browser_->profile(); | 375 Profile* profile = browser_->profile(); |
452 theme_service_ = GtkThemeService::GetFrom(profile); | 376 theme_service_ = GtkThemeService::GetFrom(profile); |
453 | 377 |
454 // Create the widget first, so we can pass it to the OmniboxViewGtk. | 378 // Create the widget first, so we can pass it to the OmniboxViewGtk. |
455 hbox_.Own(gtk_hbox_new(FALSE, InnerPadding())); | 379 hbox_.Own(gtk_hbox_new(FALSE, InnerPadding())); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()), | 524 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()), |
601 content_setting_view->widget(), FALSE, FALSE, 0); | 525 content_setting_view->widget(), FALSE, FALSE, 0); |
602 } | 526 } |
603 | 527 |
604 page_action_hbox_.Own(gtk_hbox_new(FALSE, InnerPadding())); | 528 page_action_hbox_.Own(gtk_hbox_new(FALSE, InnerPadding())); |
605 gtk_widget_set_name(page_action_hbox_.get(), | 529 gtk_widget_set_name(page_action_hbox_.get(), |
606 "chrome-page-action-hbox"); | 530 "chrome-page-action-hbox"); |
607 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), | 531 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), |
608 FALSE, FALSE, 0); | 532 FALSE, FALSE, 0); |
609 | 533 |
610 #if defined(ENABLE_WEB_INTENTS) | |
611 web_intents_hbox_.Own(gtk_hbox_new(FALSE, InnerPadding())); | |
612 gtk_widget_set_name(web_intents_hbox_.get(), | |
613 "chrome-web-intents-hbox"); | |
614 gtk_box_pack_end(GTK_BOX(hbox_.get()), web_intents_hbox_.get(), | |
615 FALSE, FALSE, 0); | |
616 gtk_box_pack_end(GTK_BOX(web_intents_hbox_.get()), | |
617 web_intents_button_view_->widget(), FALSE, FALSE, 0); | |
618 #endif | |
619 | |
620 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s | 534 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s |
621 // size-allocate so we can do proper resizing and eliding on | 535 // size-allocate so we can do proper resizing and eliding on |
622 // |security_info_label_|. | 536 // |security_info_label_|. |
623 g_signal_connect(hbox_.get(), "size-allocate", | 537 g_signal_connect(hbox_.get(), "size-allocate", |
624 G_CALLBACK(&OnHboxSizeAllocateThunk), this); | 538 G_CALLBACK(&OnHboxSizeAllocateThunk), this); |
625 | 539 |
626 registrar_.Add(this, | 540 registrar_.Add(this, |
627 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 541 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
628 content::Source<ThemeService>(theme_service_)); | 542 content::Source<ThemeService>(theme_service_)); |
629 registrar_.Add(this, | 543 registrar_.Add(this, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 return NULL; | 657 return NULL; |
744 } | 658 } |
745 | 659 |
746 void LocationBarViewGtk::Update(const WebContents* contents) { | 660 void LocationBarViewGtk::Update(const WebContents* contents) { |
747 UpdateZoomIcon(); | 661 UpdateZoomIcon(); |
748 UpdateScriptBubbleIcon(); | 662 UpdateScriptBubbleIcon(); |
749 UpdateStarIcon(); | 663 UpdateStarIcon(); |
750 UpdateSiteTypeArea(); | 664 UpdateSiteTypeArea(); |
751 UpdateContentSettingsIcons(); | 665 UpdateContentSettingsIcons(); |
752 UpdatePageActions(); | 666 UpdatePageActions(); |
753 #if defined(ENABLE_WEB_INTENTS) | |
754 UpdateWebIntentsButton(); | |
755 #endif | |
756 location_entry_->Update(contents); | 667 location_entry_->Update(contents); |
757 // The security level (background color) could have changed, etc. | 668 // The security level (background color) could have changed, etc. |
758 if (theme_service_->UsingNativeTheme()) { | 669 if (theme_service_->UsingNativeTheme()) { |
759 // In GTK mode, we need our parent to redraw, as it draws the text entry | 670 // In GTK mode, we need our parent to redraw, as it draws the text entry |
760 // border. | 671 // border. |
761 gtk_widget_queue_draw(gtk_widget_get_parent(widget())); | 672 gtk_widget_queue_draw(gtk_widget_get_parent(widget())); |
762 } else { | 673 } else { |
763 gtk_widget_queue_draw(widget()); | 674 gtk_widget_queue_draw(widget()); |
764 } | 675 } |
765 ZoomBubbleGtk::CloseBubble(); | 676 ZoomBubbleGtk::CloseBubble(); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 size_t count_before = page_action_views_.size(); | 948 size_t count_before = page_action_views_.size(); |
1038 page_action_views_.clear(); | 949 page_action_views_.clear(); |
1039 if (page_action_views_.size() != count_before) { | 950 if (page_action_views_.size() != count_before) { |
1040 content::NotificationService::current()->Notify( | 951 content::NotificationService::current()->Notify( |
1041 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 952 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
1042 content::Source<LocationBar>(this), | 953 content::Source<LocationBar>(this), |
1043 content::NotificationService::NoDetails()); | 954 content::NotificationService::NoDetails()); |
1044 } | 955 } |
1045 } | 956 } |
1046 | 957 |
1047 #if defined(ENABLE_WEB_INTENTS) | |
1048 void LocationBarViewGtk::UpdateWebIntentsButton() { | |
1049 web_intents_button_view_->Update(GetWebContents()); | |
1050 gtk_widget_set_visible(web_intents_hbox_.get(), | |
1051 web_intents_button_view_->IsVisible()); | |
1052 } | |
1053 #endif | |
1054 | |
1055 void LocationBarViewGtk::UpdateOpenPDFInReaderPrompt() { | 958 void LocationBarViewGtk::UpdateOpenPDFInReaderPrompt() { |
1056 // Not implemented on Gtk. | 959 // Not implemented on Gtk. |
1057 } | 960 } |
1058 | 961 |
1059 void LocationBarViewGtk::SaveStateToContents(WebContents* contents) { | 962 void LocationBarViewGtk::SaveStateToContents(WebContents* contents) { |
1060 location_entry_->SaveStateToTab(contents); | 963 location_entry_->SaveStateToTab(contents); |
1061 } | 964 } |
1062 | 965 |
1063 void LocationBarViewGtk::Revert() { | 966 void LocationBarViewGtk::Revert() { |
1064 location_entry_->RevertAll(); | 967 location_entry_->RevertAll(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 1, 1, 0, 0); | 1089 1, 1, 0, 0); |
1187 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), | 1090 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), |
1188 1, 1, 0, 0); | 1091 1, 1, 0, 0); |
1189 } | 1092 } |
1190 | 1093 |
1191 UpdateZoomIcon(); | 1094 UpdateZoomIcon(); |
1192 UpdateScriptBubbleIcon(); | 1095 UpdateScriptBubbleIcon(); |
1193 UpdateStarIcon(); | 1096 UpdateStarIcon(); |
1194 UpdateSiteTypeArea(); | 1097 UpdateSiteTypeArea(); |
1195 UpdateContentSettingsIcons(); | 1098 UpdateContentSettingsIcons(); |
1196 #if defined(ENABLE_WEB_INTENTS) | |
1197 UpdateWebIntentsButton(); | |
1198 #endif | |
1199 break; | 1099 break; |
1200 } | 1100 } |
1201 | 1101 |
1202 default: | 1102 default: |
1203 NOTREACHED(); | 1103 NOTREACHED(); |
1204 } | 1104 } |
1205 } | 1105 } |
1206 | 1106 |
1207 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, | 1107 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, |
1208 GdkEventExpose* event) { | 1108 GdkEventExpose* event) { |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2199 } | 2099 } |
2200 | 2100 |
2201 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( | 2101 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
2202 ExtensionAction* action) { | 2102 ExtensionAction* action) { |
2203 ExtensionPopupGtk::Show( | 2103 ExtensionPopupGtk::Show( |
2204 action->GetPopupUrl(current_tab_id_), | 2104 action->GetPopupUrl(current_tab_id_), |
2205 owner_->browser_, | 2105 owner_->browser_, |
2206 event_box_.get(), | 2106 event_box_.get(), |
2207 ExtensionPopupGtk::SHOW_AND_INSPECT); | 2107 ExtensionPopupGtk::SHOW_AND_INSPECT); |
2208 } | 2108 } |
OLD | NEW |