Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/ui/gtk/location_bar_view_gtk.cc

Issue 10796116: [Web Intents] Basic location bar UI for window disposition picker affordance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add LocationBar method to test mock. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/gtk/location_bar_view_gtk.h ('k') | chrome/browser/ui/omnibox/location_bar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h" 53 #include "chrome/browser/ui/gtk/content_setting_bubble_gtk.h"
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/view_id_util.h" 61 #include "chrome/browser/ui/gtk/view_id_util.h"
62 #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h" 62 #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h"
63 #include "chrome/browser/ui/intents/web_intent_picker_controller.h"
63 #include "chrome/browser/ui/omnibox/location_bar_util.h" 64 #include "chrome/browser/ui/omnibox/location_bar_util.h"
64 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" 65 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h"
65 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 66 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
66 #include "chrome/browser/ui/tab_contents/tab_contents.h" 67 #include "chrome/browser/ui/tab_contents/tab_contents.h"
67 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h" 68 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h"
68 #include "chrome/browser/ui/zoom/zoom_controller.h" 69 #include "chrome/browser/ui/zoom/zoom_controller.h"
69 #include "chrome/common/chrome_notification_types.h" 70 #include "chrome/common/chrome_notification_types.h"
70 #include "chrome/common/chrome_switches.h" 71 #include "chrome/common/chrome_switches.h"
71 #include "chrome/common/extensions/extension.h" 72 #include "chrome/common/extensions/extension.h"
72 #include "chrome/common/extensions/extension_action.h" 73 #include "chrome/common/extensions/extension_action.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // Colors used to draw the Tab to Search rounded bubble. 132 // Colors used to draw the Tab to Search rounded bubble.
132 const GdkColor kKeywordBackgroundColor = GDK_COLOR_RGB(0xf0, 0xf4, 0xfa); 133 const GdkColor kKeywordBackgroundColor = GDK_COLOR_RGB(0xf0, 0xf4, 0xfa);
133 const GdkColor kKeywordBorderColor = GDK_COLOR_RGB(0xcb, 0xde, 0xf7); 134 const GdkColor kKeywordBorderColor = GDK_COLOR_RGB(0xcb, 0xde, 0xf7);
134 135
135 // Use weak gray for showing search and keyword hint text. 136 // Use weak gray for showing search and keyword hint text.
136 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75); 137 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75);
137 138
138 // Size of the rounding of the "Search site for:" box. 139 // Size of the rounding of the "Search site for:" box.
139 const int kCornerSize = 3; 140 const int kCornerSize = 3;
140 141
141 // Default page tool animation time (open and close). 142 // Default page tool animation time (open and close). In ms.
142 const int kPageToolAnimationTime = 150; 143 const int kPageToolAnimationTime = 150;
143 144
144 // The time, in ms, that the content setting label is fully displayed, for the 145 // The time, in ms, that the content setting label is fully displayed, for the
145 // cases where we animate it into and out of view. 146 // cases where we animate it into and out of view.
146 const int kContentSettingImageDisplayTime = 3200; 147 const int kContentSettingImageDisplayTime = 3200;
147 // The time, in ms, of the animation (open and close). 148 // The time, in ms, of the animation (open and close).
148 const int kContentSettingImageAnimationTime = 150; 149 const int kContentSettingImageAnimationTime = 150;
149 150
151 // Animation opening time for web intents button (in ms).
152 const int kWebIntentsButtonAnimationTime = 150;
153
150 // Color of border of content setting area (icon/label). 154 // Color of border of content setting area (icon/label).
151 const GdkColor kContentSettingBorderColor = GDK_COLOR_RGB(0xe9, 0xb9, 0x66); 155 const GdkColor kContentSettingBorderColor = GDK_COLOR_RGB(0xe9, 0xb9, 0x66);
152 // Colors for the background gradient. 156 // Colors for the background gradient.
153 const GdkColor kContentSettingTopColor = GDK_COLOR_RGB(0xff, 0xf8, 0xd4); 157 const GdkColor kContentSettingTopColor = GDK_COLOR_RGB(0xff, 0xf8, 0xd4);
154 const GdkColor kContentSettingBottomColor = GDK_COLOR_RGB(0xff, 0xe6, 0xaf); 158 const GdkColor kContentSettingBottomColor = GDK_COLOR_RGB(0xff, 0xe6, 0xaf);
155 159
160 // Styling for gray button.
161 const GdkColor kGrayBorderColor = GDK_COLOR_RGB(0xa0, 0xa0, 0xa0);
162 const GdkColor kTopColorGray = GDK_COLOR_RGB(0xe5, 0xe5, 0xe5);
163 const GdkColor kBottomColorGray = GDK_COLOR_RGB(0xd0, 0xd0, 0xd0);
164
156 // If widget is visible, increment the int pointed to by count. 165 // If widget is visible, increment the int pointed to by count.
157 // Suitible for use with gtk_container_foreach. 166 // Suitible for use with gtk_container_foreach.
158 void CountVisibleWidgets(GtkWidget* widget, gpointer count) { 167 void CountVisibleWidgets(GtkWidget* widget, gpointer count) {
159 if (gtk_widget_get_visible(widget)) 168 if (gtk_widget_get_visible(widget))
160 *static_cast<int*>(count) += 1; 169 *static_cast<int*>(count) += 1;
161 } 170 }
162 171
163 class ContentSettingImageViewGtk : public LocationBarViewGtk::PageToolViewGtk, 172 class ContentSettingImageViewGtk : public LocationBarViewGtk::PageToolViewGtk,
164 public BubbleDelegateGtk { 173 public BubbleDelegateGtk {
165 public: 174 public:
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 profile, tab_contents->web_contents()); 307 profile, tab_contents->web_contents());
299 return; 308 return;
300 } 309 }
301 310
302 void ContentSettingImageViewGtk::BubbleClosing( 311 void ContentSettingImageViewGtk::BubbleClosing(
303 BubbleGtk* bubble, 312 BubbleGtk* bubble,
304 bool closed_by_escape) { 313 bool closed_by_escape) {
305 content_setting_bubble_ = NULL; 314 content_setting_bubble_ = NULL;
306 } 315 }
307 316
317 class WebIntentsButtonViewGtk : public LocationBarViewGtk::PageToolViewGtk {
318 public:
319 explicit WebIntentsButtonViewGtk(const LocationBarViewGtk* parent)
320 : LocationBarViewGtk::PageToolViewGtk(parent) {
321 animation_.SetSlideDuration(kWebIntentsButtonAnimationTime);
322 }
323 virtual ~WebIntentsButtonViewGtk() {}
308 324
325 // PageToolViewGtk
326 virtual void Update(TabContents* tab_contents) OVERRIDE;
327
328 private:
329 // PageToolViewGtk
330 virtual GdkColor button_border_color() const OVERRIDE;
331 virtual GdkColor gradient_top_color() const OVERRIDE;
332 virtual GdkColor gradient_bottom_color() const OVERRIDE;
333 virtual void OnClick(GtkWidget* sender) OVERRIDE;
334
335 DISALLOW_COPY_AND_ASSIGN(WebIntentsButtonViewGtk);
336 };
337
338 void WebIntentsButtonViewGtk::Update(
339 TabContents* tab_contents) {
340 if (!tab_contents ||
341 !tab_contents->web_intent_picker_controller() ||
342 !tab_contents->web_intent_picker_controller()->
343 ShowLocationBarPickerTool()) {
344 gtk_widget_hide(widget());
345 return;
346 }
347
348 gtk_widget_set_tooltip_text(widget(),
349 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str());
350 gtk_widget_show_all(widget());
351
352 gtk_label_set_text(GTK_LABEL(label_.get()),
353 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str());
354
355 StartAnimating();
356 }
357
358 void WebIntentsButtonViewGtk::OnClick(GtkWidget* sender) {
359 // TODO(gbillock): implement
360 }
361
362 GdkColor WebIntentsButtonViewGtk::button_border_color() const {
363 return kGrayBorderColor;
364 }
365
366 GdkColor WebIntentsButtonViewGtk::gradient_top_color() const {
367 return kTopColorGray;
368 }
369
370 GdkColor WebIntentsButtonViewGtk::gradient_bottom_color() const {
371 return kBottomColorGray;
372 }
309 373
310 } // namespace 374 } // namespace
311 375
312 //////////////////////////////////////////////////////////////////////////////// 376 ////////////////////////////////////////////////////////////////////////////////
313 // LocationBarViewGtk 377 // LocationBarViewGtk
314 378
315 // static 379 // static
316 const GdkColor LocationBarViewGtk::kBackgroundColor = 380 const GdkColor LocationBarViewGtk::kBackgroundColor =
317 GDK_COLOR_RGB(255, 255, 255); 381 GDK_COLOR_RGB(255, 255, 255);
318 382
319 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) 383 LocationBarViewGtk::LocationBarViewGtk(Browser* browser)
320 : zoom_image_(NULL), 384 : zoom_image_(NULL),
321 star_image_(NULL), 385 star_image_(NULL),
322 starred_(false), 386 starred_(false),
323 chrome_to_mobile_image_(NULL), 387 chrome_to_mobile_image_(NULL),
324 site_type_alignment_(NULL), 388 site_type_alignment_(NULL),
325 site_type_event_box_(NULL), 389 site_type_event_box_(NULL),
326 location_icon_image_(NULL), 390 location_icon_image_(NULL),
327 drag_icon_(NULL), 391 drag_icon_(NULL),
328 enable_location_drag_(false), 392 enable_location_drag_(false),
329 security_info_label_(NULL), 393 security_info_label_(NULL),
394 web_intents_button_view_(new WebIntentsButtonViewGtk(this)),
330 tab_to_search_alignment_(NULL), 395 tab_to_search_alignment_(NULL),
331 tab_to_search_box_(NULL), 396 tab_to_search_box_(NULL),
332 tab_to_search_full_label_(NULL), 397 tab_to_search_full_label_(NULL),
333 tab_to_search_partial_label_(NULL), 398 tab_to_search_partial_label_(NULL),
334 tab_to_search_hint_(NULL), 399 tab_to_search_hint_(NULL),
335 tab_to_search_hint_leading_label_(NULL), 400 tab_to_search_hint_leading_label_(NULL),
336 tab_to_search_hint_icon_(NULL), 401 tab_to_search_hint_icon_(NULL),
337 tab_to_search_hint_trailing_label_(NULL), 402 tab_to_search_hint_trailing_label_(NULL),
338 command_updater_(browser->command_controller()->command_updater()), 403 command_updater_(browser->command_controller()->command_updater()),
339 toolbar_model_(browser->toolbar_model()), 404 toolbar_model_(browser->toolbar_model()),
(...skipping 12 matching lines...) Expand all
352 } 417 }
353 418
354 LocationBarViewGtk::~LocationBarViewGtk() { 419 LocationBarViewGtk::~LocationBarViewGtk() {
355 // All of our widgets should be children of / owned by the alignment. 420 // All of our widgets should be children of / owned by the alignment.
356 zoom_.Destroy(); 421 zoom_.Destroy();
357 star_.Destroy(); 422 star_.Destroy();
358 chrome_to_mobile_view_.Destroy(); 423 chrome_to_mobile_view_.Destroy();
359 hbox_.Destroy(); 424 hbox_.Destroy();
360 content_setting_hbox_.Destroy(); 425 content_setting_hbox_.Destroy();
361 page_action_hbox_.Destroy(); 426 page_action_hbox_.Destroy();
427 web_intents_hbox_.Destroy();
362 } 428 }
363 429
364 void LocationBarViewGtk::Init(bool popup_window_mode) { 430 void LocationBarViewGtk::Init(bool popup_window_mode) {
365 popup_window_mode_ = popup_window_mode; 431 popup_window_mode_ = popup_window_mode;
366 432
367 Profile* profile = browser_->profile(); 433 Profile* profile = browser_->profile();
368 theme_service_ = GtkThemeService::GetFrom(profile); 434 theme_service_ = GtkThemeService::GetFrom(profile);
369 435
370 // Create the widget first, so we can pass it to the OmniboxViewGtk. 436 // Create the widget first, so we can pass it to the OmniboxViewGtk.
371 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); 437 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()), 588 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()),
523 content_setting_view->widget(), FALSE, FALSE, 0); 589 content_setting_view->widget(), FALSE, FALSE, 0);
524 } 590 }
525 591
526 page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); 592 page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
527 gtk_widget_set_name(page_action_hbox_.get(), 593 gtk_widget_set_name(page_action_hbox_.get(),
528 "chrome-page-action-hbox"); 594 "chrome-page-action-hbox");
529 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), 595 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(),
530 FALSE, FALSE, 0); 596 FALSE, FALSE, 0);
531 597
598 web_intents_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding));
599 gtk_widget_set_name(web_intents_hbox_.get(),
600 "chrome-web-intents-hbox");
601 gtk_box_pack_end(GTK_BOX(hbox_.get()), web_intents_hbox_.get(),
602 FALSE, FALSE, 0);
603 gtk_box_pack_end(GTK_BOX(web_intents_hbox_.get()),
604 web_intents_button_view_->widget(), FALSE, FALSE, 0);
605
532 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s 606 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s
533 // size-allocate so we can do proper resizing and eliding on 607 // size-allocate so we can do proper resizing and eliding on
534 // |security_info_label_|. 608 // |security_info_label_|.
535 g_signal_connect(hbox_.get(), "size-allocate", 609 g_signal_connect(hbox_.get(), "size-allocate",
536 G_CALLBACK(&OnHboxSizeAllocateThunk), this); 610 G_CALLBACK(&OnHboxSizeAllocateThunk), this);
537 611
538 registrar_.Add(this, 612 registrar_.Add(this,
539 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 613 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
540 content::Source<ThemeService>(theme_service_)); 614 content::Source<ThemeService>(theme_service_));
541 registrar_.Add(this, 615 registrar_.Add(this,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 return NULL; 727 return NULL;
654 } 728 }
655 729
656 void LocationBarViewGtk::Update(const WebContents* contents) { 730 void LocationBarViewGtk::Update(const WebContents* contents) {
657 UpdateZoomIcon(); 731 UpdateZoomIcon();
658 UpdateStarIcon(); 732 UpdateStarIcon();
659 UpdateChromeToMobileIcon(); 733 UpdateChromeToMobileIcon();
660 UpdateSiteTypeArea(); 734 UpdateSiteTypeArea();
661 UpdateContentSettingsIcons(); 735 UpdateContentSettingsIcons();
662 UpdatePageActions(); 736 UpdatePageActions();
737 UpdateWebIntentsButton();
663 location_entry_->Update(contents); 738 location_entry_->Update(contents);
664 // The security level (background color) could have changed, etc. 739 // The security level (background color) could have changed, etc.
665 if (theme_service_->UsingNativeTheme()) { 740 if (theme_service_->UsingNativeTheme()) {
666 // In GTK mode, we need our parent to redraw, as it draws the text entry 741 // In GTK mode, we need our parent to redraw, as it draws the text entry
667 // border. 742 // border.
668 gtk_widget_queue_draw(gtk_widget_get_parent(widget())); 743 gtk_widget_queue_draw(gtk_widget_get_parent(widget()));
669 } else { 744 } else {
670 gtk_widget_queue_draw(widget()); 745 gtk_widget_queue_draw(widget());
671 } 746 }
672 } 747 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 size_t count_before = page_action_views_.size(); 1010 size_t count_before = page_action_views_.size();
936 page_action_views_.clear(); 1011 page_action_views_.clear();
937 if (page_action_views_.size() != count_before) { 1012 if (page_action_views_.size() != count_before) {
938 content::NotificationService::current()->Notify( 1013 content::NotificationService::current()->Notify(
939 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, 1014 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED,
940 content::Source<LocationBar>(this), 1015 content::Source<LocationBar>(this),
941 content::NotificationService::NoDetails()); 1016 content::NotificationService::NoDetails());
942 } 1017 }
943 } 1018 }
944 1019
1020 void LocationBarViewGtk::UpdateWebIntentsButton() {
1021 web_intents_button_view_->Update(GetTabContents());
1022 gtk_widget_set_visible(web_intents_hbox_.get(),
1023 web_intents_button_view_->IsVisible());
1024 }
1025
945 void LocationBarViewGtk::SaveStateToContents(WebContents* contents) { 1026 void LocationBarViewGtk::SaveStateToContents(WebContents* contents) {
946 location_entry_->SaveStateToTab(contents); 1027 location_entry_->SaveStateToTab(contents);
947 } 1028 }
948 1029
949 void LocationBarViewGtk::Revert() { 1030 void LocationBarViewGtk::Revert() {
950 location_entry_->RevertAll(); 1031 location_entry_->RevertAll();
951 } 1032 }
952 1033
953 const OmniboxView* LocationBarViewGtk::GetLocationEntry() const { 1034 const OmniboxView* LocationBarViewGtk::GetLocationEntry() const {
954 return location_entry_.get(); 1035 return location_entry_.get();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 1, 1, 0, 0); 1158 1, 1, 0, 0);
1078 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), 1159 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_),
1079 1, 1, 0, 0); 1160 1, 1, 0, 0);
1080 } 1161 }
1081 1162
1082 UpdateZoomIcon(); 1163 UpdateZoomIcon();
1083 UpdateStarIcon(); 1164 UpdateStarIcon();
1084 UpdateChromeToMobileIcon(); 1165 UpdateChromeToMobileIcon();
1085 UpdateSiteTypeArea(); 1166 UpdateSiteTypeArea();
1086 UpdateContentSettingsIcons(); 1167 UpdateContentSettingsIcons();
1168 UpdateWebIntentsButton();
1087 break; 1169 break;
1088 } 1170 }
1089 1171
1090 default: 1172 default:
1091 NOTREACHED(); 1173 NOTREACHED();
1092 } 1174 }
1093 } 1175 }
1094 1176
1095 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, 1177 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
1096 GdkEventExpose* event) { 1178 GdkEventExpose* event) {
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 } 2134 }
2053 2135
2054 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( 2136 void LocationBarViewGtk::PageActionViewGtk::InspectPopup(
2055 ExtensionAction* action) { 2137 ExtensionAction* action) {
2056 ExtensionPopupGtk::Show( 2138 ExtensionPopupGtk::Show(
2057 action->GetPopupUrl(current_tab_id_), 2139 action->GetPopupUrl(current_tab_id_),
2058 owner_->browser_, 2140 owner_->browser_,
2059 event_box_.get(), 2141 event_box_.get(),
2060 ExtensionPopupGtk::SHOW_AND_INSPECT); 2142 ExtensionPopupGtk::SHOW_AND_INSPECT);
2061 } 2143 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/location_bar_view_gtk.h ('k') | chrome/browser/ui/omnibox/location_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698