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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75); | 134 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75); |
134 | 135 |
135 // Size of the rounding of the "Search site for:" box. | 136 // Size of the rounding of the "Search site for:" box. |
136 const int kCornerSize = 3; | 137 const int kCornerSize = 3; |
137 | 138 |
138 // The time, in ms, that the content setting label is fully displayed, for the | 139 // The time, in ms, that the content setting label is fully displayed, for the |
139 // cases where we animate it into and out of view. | 140 // cases where we animate it into and out of view. |
140 const int kContentSettingImageDisplayTime = 3200; | 141 const int kContentSettingImageDisplayTime = 3200; |
141 // The time, in ms, of the animation (open and close). | 142 // The time, in ms, of the animation (open and close). |
142 const int kContentSettingImageAnimationTime = 150; | 143 const int kContentSettingImageAnimationTime = 150; |
144 const int kPageToolAnimationTime = 1000; | |
143 | 145 |
144 // Color of border of content setting area (icon/label). | 146 // Color of border of content setting area (icon/label). |
145 const GdkColor kContentSettingBorderColor = GDK_COLOR_RGB(0xe9, 0xb9, 0x66); | 147 const GdkColor kContentSettingBorderColor = GDK_COLOR_RGB(0xe9, 0xb9, 0x66); |
146 // Colors for the background gradient. | 148 // Colors for the background gradient. |
147 const double kContentSettingTopColor[] = { 0xff / 255.0, | 149 const GdkColor kContentSettingTopColor = GDK_COLOR_RGB(0xff, 0xf8, 0xd4); |
148 0xf8 / 255.0, | 150 const GdkColor kContentSettingBottomColor = GDK_COLOR_RGB(0xff, 0xe6, 0xaf); |
149 0xd4 / 255.0 }; | 151 |
150 const double kContentSettingBottomColor[] = { 0xff / 255.0, | 152 const GdkColor kGrayBorderColor = GDK_COLOR_RGB(0xa0, 0xa0, 0xa0); |
151 0xe6 / 255.0, | 153 const GdkColor kTopColorGray = GDK_COLOR_RGB(0xe5, 0xe5, 0xe5); |
152 0xaf / 255.0 }; | 154 const GdkColor kBottomColorGray = GDK_COLOR_RGB(0xd0, 0xd0, 0xd0); |
153 | 155 |
154 // If widget is visible, increment the int pointed to by count. | 156 // If widget is visible, increment the int pointed to by count. |
155 // Suitible for use with gtk_container_foreach. | 157 // Suitible for use with gtk_container_foreach. |
156 void CountVisibleWidgets(GtkWidget* widget, gpointer count) { | 158 void CountVisibleWidgets(GtkWidget* widget, gpointer count) { |
157 if (gtk_widget_get_visible(widget)) | 159 if (gtk_widget_get_visible(widget)) |
158 *static_cast<int*>(count) += 1; | 160 *static_cast<int*>(count) += 1; |
159 } | 161 } |
160 | 162 |
161 } // namespace | 163 } // namespace |
162 | 164 |
163 //////////////////////////////////////////////////////////////////////////////// | 165 //////////////////////////////////////////////////////////////////////////////// |
164 // LocationBarViewGtk | 166 // LocationBarViewGtk |
165 | 167 |
166 // static | 168 // static |
167 const GdkColor LocationBarViewGtk::kBackgroundColor = | 169 const GdkColor LocationBarViewGtk::kBackgroundColor = |
168 GDK_COLOR_RGB(255, 255, 255); | 170 GDK_COLOR_RGB(255, 255, 255); |
169 | 171 |
170 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) | 172 LocationBarViewGtk::LocationBarViewGtk(Browser* browser) |
171 : zoom_image_(NULL), | 173 : zoom_image_(NULL), |
172 star_image_(NULL), | 174 star_image_(NULL), |
173 starred_(false), | 175 starred_(false), |
174 chrome_to_mobile_image_(NULL), | 176 chrome_to_mobile_image_(NULL), |
175 site_type_alignment_(NULL), | 177 site_type_alignment_(NULL), |
176 site_type_event_box_(NULL), | 178 site_type_event_box_(NULL), |
177 location_icon_image_(NULL), | 179 location_icon_image_(NULL), |
178 drag_icon_(NULL), | 180 drag_icon_(NULL), |
179 enable_location_drag_(false), | 181 enable_location_drag_(false), |
180 security_info_label_(NULL), | 182 security_info_label_(NULL), |
183 web_intents_tool_view_(this), | |
181 tab_to_search_alignment_(NULL), | 184 tab_to_search_alignment_(NULL), |
182 tab_to_search_box_(NULL), | 185 tab_to_search_box_(NULL), |
183 tab_to_search_full_label_(NULL), | 186 tab_to_search_full_label_(NULL), |
184 tab_to_search_partial_label_(NULL), | 187 tab_to_search_partial_label_(NULL), |
185 tab_to_search_hint_(NULL), | 188 tab_to_search_hint_(NULL), |
186 tab_to_search_hint_leading_label_(NULL), | 189 tab_to_search_hint_leading_label_(NULL), |
187 tab_to_search_hint_icon_(NULL), | 190 tab_to_search_hint_icon_(NULL), |
188 tab_to_search_hint_trailing_label_(NULL), | 191 tab_to_search_hint_trailing_label_(NULL), |
189 command_updater_(browser->command_controller()->command_updater()), | 192 command_updater_(browser->command_controller()->command_updater()), |
190 toolbar_model_(browser->toolbar_model()), | 193 toolbar_model_(browser->toolbar_model()), |
(...skipping 12 matching lines...) Expand all Loading... | |
203 } | 206 } |
204 | 207 |
205 LocationBarViewGtk::~LocationBarViewGtk() { | 208 LocationBarViewGtk::~LocationBarViewGtk() { |
206 // All of our widgets should be children of / owned by the alignment. | 209 // All of our widgets should be children of / owned by the alignment. |
207 zoom_.Destroy(); | 210 zoom_.Destroy(); |
208 star_.Destroy(); | 211 star_.Destroy(); |
209 chrome_to_mobile_view_.Destroy(); | 212 chrome_to_mobile_view_.Destroy(); |
210 hbox_.Destroy(); | 213 hbox_.Destroy(); |
211 content_setting_hbox_.Destroy(); | 214 content_setting_hbox_.Destroy(); |
212 page_action_hbox_.Destroy(); | 215 page_action_hbox_.Destroy(); |
216 web_intents_hbox_.Destroy(); | |
213 } | 217 } |
214 | 218 |
215 void LocationBarViewGtk::Init(bool popup_window_mode) { | 219 void LocationBarViewGtk::Init(bool popup_window_mode) { |
216 popup_window_mode_ = popup_window_mode; | 220 popup_window_mode_ = popup_window_mode; |
217 | 221 |
218 Profile* profile = browser_->profile(); | 222 Profile* profile = browser_->profile(); |
219 theme_service_ = GtkThemeService::GetFrom(profile); | 223 theme_service_ = GtkThemeService::GetFrom(profile); |
220 | 224 |
221 // Create the widget first, so we can pass it to the OmniboxViewGtk. | 225 // Create the widget first, so we can pass it to the OmniboxViewGtk. |
222 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); | 226 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()), | 362 gtk_box_pack_end(GTK_BOX(content_setting_hbox_.get()), |
359 content_setting_view->widget(), FALSE, FALSE, 0); | 363 content_setting_view->widget(), FALSE, FALSE, 0); |
360 } | 364 } |
361 | 365 |
362 page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); | 366 page_action_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); |
363 gtk_widget_set_name(page_action_hbox_.get(), | 367 gtk_widget_set_name(page_action_hbox_.get(), |
364 "chrome-page-action-hbox"); | 368 "chrome-page-action-hbox"); |
365 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), | 369 gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), |
366 FALSE, FALSE, 0); | 370 FALSE, FALSE, 0); |
367 | 371 |
372 web_intents_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); | |
373 gtk_widget_set_name(web_intents_hbox_.get(), | |
374 "chrome-web-intents-hbox"); | |
375 gtk_box_pack_end(GTK_BOX(hbox_.get()), web_intents_hbox_.get(), | |
376 FALSE, FALSE, 0); | |
377 gtk_box_pack_end(GTK_BOX(web_intents_hbox_.get()), | |
378 web_intents_tool_view_.widget(), FALSE, FALSE, 0); | |
379 | |
368 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s | 380 // Now that we've created the widget hierarchy, connect to the main |hbox_|'s |
369 // size-allocate so we can do proper resizing and eliding on | 381 // size-allocate so we can do proper resizing and eliding on |
370 // |security_info_label_|. | 382 // |security_info_label_|. |
371 g_signal_connect(hbox_.get(), "size-allocate", | 383 g_signal_connect(hbox_.get(), "size-allocate", |
372 G_CALLBACK(&OnHboxSizeAllocateThunk), this); | 384 G_CALLBACK(&OnHboxSizeAllocateThunk), this); |
373 | 385 |
374 registrar_.Add(this, | 386 registrar_.Add(this, |
375 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 387 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
376 content::Source<ThemeService>(theme_service_)); | 388 content::Source<ThemeService>(theme_service_)); |
377 registrar_.Add(this, | 389 registrar_.Add(this, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 return NULL; | 501 return NULL; |
490 } | 502 } |
491 | 503 |
492 void LocationBarViewGtk::Update(const WebContents* contents) { | 504 void LocationBarViewGtk::Update(const WebContents* contents) { |
493 UpdateZoomIcon(); | 505 UpdateZoomIcon(); |
494 UpdateStarIcon(); | 506 UpdateStarIcon(); |
495 UpdateChromeToMobileIcon(); | 507 UpdateChromeToMobileIcon(); |
496 UpdateSiteTypeArea(); | 508 UpdateSiteTypeArea(); |
497 UpdateContentSettingsIcons(); | 509 UpdateContentSettingsIcons(); |
498 UpdatePageActions(); | 510 UpdatePageActions(); |
511 UpdateWebIntentsTool(); | |
499 location_entry_->Update(contents); | 512 location_entry_->Update(contents); |
500 // The security level (background color) could have changed, etc. | 513 // The security level (background color) could have changed, etc. |
501 if (theme_service_->UsingNativeTheme()) { | 514 if (theme_service_->UsingNativeTheme()) { |
502 // In GTK mode, we need our parent to redraw, as it draws the text entry | 515 // In GTK mode, we need our parent to redraw, as it draws the text entry |
503 // border. | 516 // border. |
504 gtk_widget_queue_draw(gtk_widget_get_parent(widget())); | 517 gtk_widget_queue_draw(gtk_widget_get_parent(widget())); |
505 } else { | 518 } else { |
506 gtk_widget_queue_draw(widget()); | 519 gtk_widget_queue_draw(widget()); |
507 } | 520 } |
508 } | 521 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 if (select_all) | 715 if (select_all) |
703 location_entry_->SelectAll(true); | 716 location_entry_->SelectAll(true); |
704 } | 717 } |
705 | 718 |
706 void LocationBarViewGtk::FocusSearch() { | 719 void LocationBarViewGtk::FocusSearch() { |
707 location_entry_->SetFocus(); | 720 location_entry_->SetFocus(); |
708 location_entry_->SetForcedQuery(); | 721 location_entry_->SetForcedQuery(); |
709 } | 722 } |
710 | 723 |
711 void LocationBarViewGtk::UpdateContentSettingsIcons() { | 724 void LocationBarViewGtk::UpdateContentSettingsIcons() { |
712 WebContents* web_contents = GetWebContents(); | |
713 bool any_visible = false; | 725 bool any_visible = false; |
714 for (ScopedVector<ContentSettingImageViewGtk>::iterator i( | 726 for (ScopedVector<ContentSettingImageViewGtk>::iterator i( |
715 content_setting_views_.begin()); | 727 content_setting_views_.begin()); |
716 i != content_setting_views_.end(); ++i) { | 728 i != content_setting_views_.end(); ++i) { |
717 (*i)->UpdateFromWebContents( | 729 (*i)->Update( |
718 toolbar_model_->input_in_progress() ? NULL : web_contents); | 730 toolbar_model_->input_in_progress() ? NULL : GetTabContents()); |
719 any_visible = (*i)->IsVisible() || any_visible; | 731 any_visible = (*i)->IsVisible() || any_visible; |
720 } | 732 } |
721 | 733 |
722 // If there are no visible content things, hide the top level box so it | 734 // If there are no visible content things, hide the top level box so it |
723 // doesn't mess with padding. | 735 // doesn't mess with padding. |
724 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); | 736 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); |
725 } | 737 } |
726 | 738 |
727 void LocationBarViewGtk::UpdatePageActions() { | 739 void LocationBarViewGtk::UpdatePageActions() { |
728 std::vector<ExtensionAction*> new_page_actions; | 740 std::vector<ExtensionAction*> new_page_actions; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 size_t count_before = page_action_views_.size(); | 784 size_t count_before = page_action_views_.size(); |
773 page_action_views_.clear(); | 785 page_action_views_.clear(); |
774 if (page_action_views_.size() != count_before) { | 786 if (page_action_views_.size() != count_before) { |
775 content::NotificationService::current()->Notify( | 787 content::NotificationService::current()->Notify( |
776 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | 788 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, |
777 content::Source<LocationBar>(this), | 789 content::Source<LocationBar>(this), |
778 content::NotificationService::NoDetails()); | 790 content::NotificationService::NoDetails()); |
779 } | 791 } |
780 } | 792 } |
781 | 793 |
794 void LocationBarViewGtk::UpdateWebIntentsTool() { | |
795 web_intents_tool_view_.Update(GetTabContents()); | |
796 gtk_widget_set_visible(web_intents_hbox_.get(), | |
797 web_intents_tool_view_.IsVisible()); | |
798 } | |
799 | |
782 void LocationBarViewGtk::SaveStateToContents(WebContents* contents) { | 800 void LocationBarViewGtk::SaveStateToContents(WebContents* contents) { |
783 location_entry_->SaveStateToTab(contents); | 801 location_entry_->SaveStateToTab(contents); |
784 } | 802 } |
785 | 803 |
786 void LocationBarViewGtk::Revert() { | 804 void LocationBarViewGtk::Revert() { |
787 location_entry_->RevertAll(); | 805 location_entry_->RevertAll(); |
788 } | 806 } |
789 | 807 |
790 const OmniboxView* LocationBarViewGtk::GetLocationEntry() const { | 808 const OmniboxView* LocationBarViewGtk::GetLocationEntry() const { |
791 return location_entry_.get(); | 809 return location_entry_.get(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 1, 1, 0, 0); | 932 1, 1, 0, 0); |
915 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), | 933 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), |
916 1, 1, 0, 0); | 934 1, 1, 0, 0); |
917 } | 935 } |
918 | 936 |
919 UpdateZoomIcon(); | 937 UpdateZoomIcon(); |
920 UpdateStarIcon(); | 938 UpdateStarIcon(); |
921 UpdateChromeToMobileIcon(); | 939 UpdateChromeToMobileIcon(); |
922 UpdateSiteTypeArea(); | 940 UpdateSiteTypeArea(); |
923 UpdateContentSettingsIcons(); | 941 UpdateContentSettingsIcons(); |
942 UpdateWebIntentsTool(); | |
924 break; | 943 break; |
925 } | 944 } |
926 | 945 |
927 default: | 946 default: |
928 NOTREACHED(); | 947 NOTREACHED(); |
929 } | 948 } |
930 } | 949 } |
931 | 950 |
932 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, | 951 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, |
933 GdkEventExpose* event) { | 952 GdkEventExpose* event) { |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1406 gtk_widget_show(tab_to_search_hint_); | 1425 gtk_widget_show(tab_to_search_hint_); |
1407 } else if (full_width < available_width) { | 1426 } else if (full_width < available_width) { |
1408 gtk_widget_show(tab_to_search_hint_leading_label_); | 1427 gtk_widget_show(tab_to_search_hint_leading_label_); |
1409 gtk_widget_show(tab_to_search_hint_trailing_label_); | 1428 gtk_widget_show(tab_to_search_hint_trailing_label_); |
1410 gtk_widget_show(tab_to_search_hint_); | 1429 gtk_widget_show(tab_to_search_hint_); |
1411 } | 1430 } |
1412 } | 1431 } |
1413 } | 1432 } |
1414 | 1433 |
1415 //////////////////////////////////////////////////////////////////////////////// | 1434 //////////////////////////////////////////////////////////////////////////////// |
1416 // LocationBarViewGtk::ContentSettingImageViewGtk | 1435 // LocationBarViewGtk::PageToolViewGtk |
1417 LocationBarViewGtk::ContentSettingImageViewGtk::ContentSettingImageViewGtk( | 1436 |
1418 ContentSettingsType content_type, | 1437 LocationBarViewGtk::PageToolViewGtk::PageToolViewGtk( |
1419 const LocationBarViewGtk* parent) | 1438 const LocationBarViewGtk* parent) |
1420 : content_setting_image_model_( | 1439 : alignment_(gtk_alignment_new(0, 0, 1, 1)), |
1421 ContentSettingImageModel::CreateContentSettingImageModel( | |
1422 content_type)), | |
1423 alignment_(gtk_alignment_new(0, 0, 1, 1)), | |
1424 event_box_(gtk_event_box_new()), | 1440 event_box_(gtk_event_box_new()), |
1425 hbox_(gtk_hbox_new(FALSE, kInnerPadding)), | 1441 hbox_(gtk_hbox_new(FALSE, kInnerPadding)), |
1426 image_(gtk_image_new()), | 1442 image_(gtk_image_new()), |
1427 label_(gtk_label_new(NULL)), | 1443 label_(gtk_label_new(NULL)), |
1428 parent_(parent), | 1444 parent_(parent), |
1429 content_setting_bubble_(NULL), | |
1430 animation_(this), | 1445 animation_(this), |
1431 weak_factory_(this) { | 1446 weak_factory_(this) { |
1432 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment_.get()), 1, 1, 0, 0); | 1447 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment_.get()), 1, 1, 0, 0); |
1433 gtk_container_add(GTK_CONTAINER(alignment_.get()), event_box_.get()); | 1448 gtk_container_add(GTK_CONTAINER(alignment_.get()), event_box_.get()); |
1434 | 1449 |
1435 // Make the event box not visible so it does not paint a background. | 1450 // Make the event box not visible so it does not paint a background. |
1436 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); | 1451 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
1437 g_signal_connect(event_box_.get(), "button-press-event", | 1452 g_signal_connect(event_box_.get(), "button-press-event", |
1438 G_CALLBACK(&OnButtonPressedThunk), this); | 1453 G_CALLBACK(&OnButtonPressedThunk), this); |
1439 g_signal_connect(event_box_.get(), "expose-event", | 1454 g_signal_connect(event_box_.get(), "expose-event", |
1440 G_CALLBACK(&OnExposeThunk), this); | 1455 G_CALLBACK(&OnExposeThunk), this); |
1441 | 1456 |
1442 gtk_widget_set_no_show_all(label_.get(), TRUE); | 1457 gtk_widget_set_no_show_all(label_.get(), TRUE); |
1443 gtk_label_set_line_wrap(GTK_LABEL(label_.get()), FALSE); | 1458 gtk_label_set_line_wrap(GTK_LABEL(label_.get()), FALSE); |
1444 | 1459 |
1445 gtk_box_pack_start(GTK_BOX(hbox_), image_.get(), FALSE, FALSE, 0); | 1460 gtk_box_pack_start(GTK_BOX(hbox_), image_.get(), FALSE, FALSE, 0); |
1446 gtk_box_pack_start(GTK_BOX(hbox_), label_.get(), FALSE, FALSE, 0); | 1461 gtk_box_pack_start(GTK_BOX(hbox_), label_.get(), FALSE, FALSE, 0); |
1447 | 1462 |
1448 gtk_container_set_border_width(GTK_CONTAINER(hbox_), kHboxBorder); | 1463 gtk_container_set_border_width(GTK_CONTAINER(hbox_), kHboxBorder); |
1449 | 1464 |
1450 gtk_container_add(GTK_CONTAINER(event_box_.get()), hbox_); | 1465 gtk_container_add(GTK_CONTAINER(event_box_.get()), hbox_); |
1451 gtk_widget_hide(widget()); | 1466 gtk_widget_hide(widget()); |
1452 | 1467 |
1453 animation_.SetSlideDuration(kContentSettingImageAnimationTime); | 1468 animation_.SetSlideDuration(kPageToolAnimationTime); |
1454 } | 1469 } |
1455 | 1470 |
1456 LocationBarViewGtk::ContentSettingImageViewGtk::~ContentSettingImageViewGtk() { | 1471 LocationBarViewGtk::PageToolViewGtk::~PageToolViewGtk() { |
1457 image_.Destroy(); | 1472 image_.Destroy(); |
1458 label_.Destroy(); | 1473 label_.Destroy(); |
1459 event_box_.Destroy(); | 1474 event_box_.Destroy(); |
1460 alignment_.Destroy(); | 1475 alignment_.Destroy(); |
1461 | |
1462 if (content_setting_bubble_) | |
1463 content_setting_bubble_->Close(); | |
1464 } | 1476 } |
1465 | 1477 |
1466 bool LocationBarViewGtk::ContentSettingImageViewGtk::IsVisible() { | 1478 GtkWidget* LocationBarViewGtk::PageToolViewGtk::widget() { |
1479 return alignment_.get(); | |
1480 } | |
1481 | |
1482 bool LocationBarViewGtk::PageToolViewGtk::IsVisible() { | |
1467 return gtk_widget_get_visible(widget()); | 1483 return gtk_widget_get_visible(widget()); |
1468 } | 1484 } |
1469 | 1485 |
1470 void LocationBarViewGtk::ContentSettingImageViewGtk::UpdateFromWebContents( | 1486 void LocationBarViewGtk::PageToolViewGtk::Update( |
Bernhard Bauer
2012/07/27 00:35:38
Where is this method called?
| |
1471 WebContents* web_contents) { | 1487 TabContents* tab_contents) { |
1472 content_setting_image_model_->UpdateFromWebContents(web_contents); | 1488 if (!tab_contents || |
1473 if (!content_setting_image_model_->is_visible()) { | 1489 !tab_contents->web_intent_picker_controller() || |
Bernhard Bauer
2012/07/27 00:35:38
This still seems to be Web Intents specific?
| |
1490 !tab_contents->web_intent_picker_controller()-> | |
1491 ShowLocationBarPickerTool()) { | |
1474 gtk_widget_hide(widget()); | 1492 gtk_widget_hide(widget()); |
1475 return; | 1493 return; |
1476 } | 1494 } |
1477 | 1495 |
1478 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), | |
1479 GtkThemeService::GetFrom(parent_->browser()->profile())->GetImageNamed( | |
1480 content_setting_image_model_->get_icon())->ToGdkPixbuf()); | |
1481 | |
1482 gtk_widget_set_tooltip_text(widget(), | 1496 gtk_widget_set_tooltip_text(widget(), |
1483 content_setting_image_model_->get_tooltip().c_str()); | 1497 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str()); |
1484 gtk_widget_show_all(widget()); | 1498 gtk_widget_show_all(widget()); |
1485 | 1499 |
1486 TabSpecificContentSettings* content_settings = NULL; | 1500 gtk_label_set_text(GTK_LABEL(label_.get()), |
1487 if (web_contents) { | 1501 l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str()); |
1488 content_settings = | |
1489 TabContents::FromWebContents(web_contents)->content_settings(); | |
1490 } | |
1491 if (!content_settings || content_settings->IsBlockageIndicated( | |
1492 content_setting_image_model_->get_content_settings_type())) | |
1493 return; | |
1494 | 1502 |
1495 // The content blockage was not yet indicated to the user. Start indication | |
1496 // animation and clear "not yet shown" flag. | |
1497 content_settings->SetBlockageHasBeenIndicated( | |
1498 content_setting_image_model_->get_content_settings_type()); | |
1499 | |
1500 int label_string_id = | |
1501 content_setting_image_model_->explanatory_string_id(); | |
1502 // If there's no string for the content type, we don't animate. | |
1503 if (!label_string_id) | |
1504 return; | |
1505 | |
1506 gtk_label_set_text(GTK_LABEL(label_.get()), | |
1507 l10n_util::GetStringUTF8(label_string_id).c_str()); | |
1508 StartAnimating(); | 1503 StartAnimating(); |
1509 } | 1504 } |
1510 | 1505 |
1511 void LocationBarViewGtk::ContentSettingImageViewGtk::StartAnimating() { | 1506 GdkColor LocationBarViewGtk::PageToolViewGtk::button_border_color() const { |
1507 return kGrayBorderColor; | |
1508 } | |
1509 | |
1510 void LocationBarViewGtk::PageToolViewGtk::StartAnimating() { | |
1512 if (animation_.IsShowing() || animation_.IsClosing()) | 1511 if (animation_.IsShowing() || animation_.IsClosing()) |
1513 return; | 1512 return; |
1514 | 1513 |
1515 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), TRUE); | 1514 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), TRUE); |
1516 gtk_util::ActAsRoundedWindow(event_box_.get(), kContentSettingBorderColor, | 1515 GdkColor border_color = button_border_color(); |
1516 gtk_util::ActAsRoundedWindow(event_box_.get(), border_color, | |
1517 kCornerSize, | 1517 kCornerSize, |
1518 gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL); | 1518 gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL); |
1519 | 1519 |
1520 gtk_widget_set_size_request(label_.get(), -1, -1); | 1520 gtk_widget_set_size_request(label_.get(), -1, -1); |
1521 gtk_widget_size_request(label_.get(), &label_req_); | 1521 gtk_widget_size_request(label_.get(), &label_req_); |
1522 gtk_widget_set_size_request(label_.get(), 0, -1); | 1522 gtk_widget_set_size_request(label_.get(), 0, -1); |
1523 gtk_widget_show(label_.get()); | 1523 gtk_widget_show(label_.get()); |
1524 | 1524 |
1525 animation_.Show(); | 1525 animation_.Show(); |
1526 } | 1526 } |
1527 | 1527 |
1528 void LocationBarViewGtk::ContentSettingImageViewGtk::CloseAnimation() { | 1528 void LocationBarViewGtk::PageToolViewGtk::CloseAnimation() { |
1529 animation_.Hide(); | 1529 animation_.Hide(); |
1530 } | 1530 } |
1531 | 1531 |
1532 void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationProgressed( | 1532 void LocationBarViewGtk::PageToolViewGtk::AnimationProgressed( |
1533 const ui::Animation* animation) { | 1533 const ui::Animation* animation) { |
1534 gtk_widget_set_size_request( | 1534 gtk_widget_set_size_request( |
1535 label_.get(), | 1535 label_.get(), |
1536 animation->GetCurrentValue() * label_req_.width, | 1536 animation->GetCurrentValue() * label_req_.width, |
1537 -1); | 1537 -1); |
1538 } | 1538 } |
1539 | 1539 |
1540 void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationEnded( | 1540 void LocationBarViewGtk::PageToolViewGtk::AnimationCanceled( |
1541 const ui::Animation* animation) { | 1541 const ui::Animation* animation) { |
1542 if (animation_.IsShowing()) { | 1542 } |
1543 MessageLoop::current()->PostDelayedTask( | 1543 |
1544 FROM_HERE, | 1544 void LocationBarViewGtk::PageToolViewGtk::AnimationEnded( |
1545 base::Bind(&ContentSettingImageViewGtk::CloseAnimation, | 1545 const ui::Animation* animation) { |
1546 weak_factory_.GetWeakPtr()), | 1546 if (!animation_.IsShowing()) { |
1547 base::TimeDelta::FromMilliseconds(kContentSettingImageDisplayTime)); | |
1548 } else { | |
1549 gtk_widget_hide(label_.get()); | 1547 gtk_widget_hide(label_.get()); |
1550 gtk_util::StopActingAsRoundedWindow(event_box_.get()); | 1548 gtk_util::StopActingAsRoundedWindow(event_box_.get()); |
1551 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); | 1549 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
1552 } | 1550 } |
1553 } | 1551 } |
1554 | 1552 |
1555 void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationCanceled( | 1553 gboolean LocationBarViewGtk::PageToolViewGtk::OnButtonPressed( |
1556 const ui::Animation* animation) { | |
1557 } | |
1558 | |
1559 gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnButtonPressed( | |
1560 GtkWidget* sender, GdkEvent* event) { | 1554 GtkWidget* sender, GdkEvent* event) { |
1561 TabContents* tab_contents = parent_->GetTabContents(); | 1555 OnClick(sender); |
1562 if (!tab_contents) | |
1563 return TRUE; | |
1564 Profile* profile = parent_->browser()->profile(); | |
1565 content_setting_bubble_ = new ContentSettingBubbleGtk( | |
1566 sender, this, | |
1567 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | |
1568 parent_->browser()->content_setting_bubble_model_delegate(), | |
1569 tab_contents, | |
1570 profile, | |
1571 content_setting_image_model_->get_content_settings_type()), | |
1572 profile, tab_contents->web_contents()); | |
1573 return TRUE; | 1556 return TRUE; |
1574 } | 1557 } |
1575 | 1558 |
1576 gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnExpose( | 1559 void LocationBarViewGtk::PageToolViewGtk::OnClick(GtkWidget* sender) { |
1560 LOG(INFO) << "CLICK!!!"; | |
1561 } | |
1562 | |
1563 GdkColor LocationBarViewGtk::PageToolViewGtk::gradient_top_color() const { | |
1564 return kTopColorGray; | |
1565 } | |
1566 | |
1567 GdkColor LocationBarViewGtk::PageToolViewGtk::gradient_bottom_color() const { | |
1568 return kBottomColorGray; | |
1569 } | |
1570 | |
1571 gboolean LocationBarViewGtk::PageToolViewGtk::OnExpose( | |
1577 GtkWidget* sender, GdkEventExpose* event) { | 1572 GtkWidget* sender, GdkEventExpose* event) { |
1578 TRACE_EVENT0("ui::gtk", | 1573 TRACE_EVENT0("ui::gtk", "LocationBarViewGtk::PageToolViewGtk::OnExpose"); |
1579 "LocationBarViewGtk::ContentSettingImageViewGtk::OnExpose"); | |
1580 | 1574 |
1581 if (!(animation_.IsShowing() || animation_.IsClosing())) | 1575 if (!(animation_.IsShowing() || animation_.IsClosing())) |
1582 return FALSE; | 1576 return FALSE; |
1583 | 1577 |
1584 GtkAllocation allocation; | 1578 GtkAllocation allocation; |
1585 gtk_widget_get_allocation(sender, &allocation); | 1579 gtk_widget_get_allocation(sender, &allocation); |
1586 const int height = allocation.height; | 1580 const int height = allocation.height; |
1587 | 1581 |
1588 cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(sender)); | 1582 cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(sender)); |
1589 gdk_cairo_rectangle(cr, &event->area); | 1583 gdk_cairo_rectangle(cr, &event->area); |
1590 cairo_clip(cr); | 1584 cairo_clip(cr); |
1591 | 1585 |
1592 cairo_pattern_t* pattern = cairo_pattern_create_linear(0, 0, 0, height); | 1586 cairo_pattern_t* pattern = cairo_pattern_create_linear(0, 0, 0, height); |
1593 | 1587 |
1594 cairo_pattern_add_color_stop_rgb(pattern, 0.0, | 1588 const GdkColor top_color = gradient_top_color(); |
1595 kContentSettingTopColor[0], | 1589 const GdkColor bottom_color = gradient_bottom_color(); |
1596 kContentSettingTopColor[1], | 1590 cairo_pattern_add_color_stop_rgb( |
1597 kContentSettingTopColor[2]); | 1591 pattern, 0.0, |
1598 cairo_pattern_add_color_stop_rgb(pattern, 1.0, | 1592 top_color.red/255.0, |
1599 kContentSettingBottomColor[0], | 1593 top_color.blue/255.0, |
1600 kContentSettingBottomColor[1], | 1594 top_color.green/255.0); |
1601 kContentSettingBottomColor[2]); | 1595 cairo_pattern_add_color_stop_rgb( |
1596 pattern, 1.0, | |
1597 bottom_color.red/255.0, | |
1598 bottom_color.blue/255.0, | |
1599 bottom_color.green/255.0); | |
1600 | |
1602 cairo_set_source(cr, pattern); | 1601 cairo_set_source(cr, pattern); |
1603 cairo_paint(cr); | 1602 cairo_paint(cr); |
1604 cairo_pattern_destroy(pattern); | 1603 cairo_pattern_destroy(pattern); |
1605 cairo_destroy(cr); | 1604 cairo_destroy(cr); |
1606 | 1605 |
1607 return FALSE; | 1606 return FALSE; |
1608 } | 1607 } |
1609 | 1608 |
1609 //////////////////////////////////////////////////////////////////////////////// | |
1610 // LocationBarViewGtk::ContentSettingImageViewGtk | |
1611 LocationBarViewGtk::ContentSettingImageViewGtk::ContentSettingImageViewGtk( | |
1612 ContentSettingsType content_type, | |
1613 const LocationBarViewGtk* parent) | |
1614 : PageToolViewGtk(parent), | |
1615 content_setting_image_model_( | |
1616 ContentSettingImageModel::CreateContentSettingImageModel( | |
1617 content_type)), | |
1618 content_setting_bubble_(NULL) { | |
1619 animation_.SetSlideDuration(kContentSettingImageAnimationTime); | |
1620 } | |
1621 | |
1622 LocationBarViewGtk::ContentSettingImageViewGtk::~ContentSettingImageViewGtk() { | |
1623 if (content_setting_bubble_) | |
1624 content_setting_bubble_->Close(); | |
1625 } | |
1626 | |
1627 void LocationBarViewGtk::ContentSettingImageViewGtk::Update( | |
1628 TabContents* tab_contents) { | |
1629 if (tab_contents) { | |
1630 content_setting_image_model_->UpdateFromWebContents( | |
1631 tab_contents->web_contents()); | |
1632 } | |
1633 if (!content_setting_image_model_->is_visible()) { | |
1634 gtk_widget_hide(widget()); | |
1635 return; | |
1636 } | |
1637 | |
1638 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), | |
1639 GtkThemeService::GetFrom(parent_->browser()->profile())->GetImageNamed( | |
1640 content_setting_image_model_->get_icon())->ToGdkPixbuf()); | |
1641 | |
1642 gtk_widget_set_tooltip_text(widget(), | |
1643 content_setting_image_model_->get_tooltip().c_str()); | |
1644 gtk_widget_show_all(widget()); | |
1645 | |
1646 if (!tab_contents) | |
1647 return; | |
1648 | |
1649 TabSpecificContentSettings* content_settings = | |
1650 tab_contents->content_settings(); | |
1651 if (!content_settings || content_settings->IsBlockageIndicated( | |
1652 content_setting_image_model_->get_content_settings_type())) | |
1653 return; | |
1654 | |
1655 // The content blockage was not yet indicated to the user. Start indication | |
1656 // animation and clear "not yet shown" flag. | |
1657 content_settings->SetBlockageHasBeenIndicated( | |
1658 content_setting_image_model_->get_content_settings_type()); | |
1659 | |
1660 int label_string_id = | |
1661 content_setting_image_model_->explanatory_string_id(); | |
1662 // If there's no string for the content type, we don't animate. | |
1663 if (!label_string_id) | |
1664 return; | |
1665 | |
1666 gtk_label_set_text(GTK_LABEL(label_.get()), | |
1667 l10n_util::GetStringUTF8(label_string_id).c_str()); | |
1668 StartAnimating(); | |
1669 } | |
1670 | |
1671 void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationEnded( | |
1672 const ui::Animation* animation) { | |
1673 if (animation_.IsShowing()) { | |
1674 MessageLoop::current()->PostDelayedTask( | |
1675 FROM_HERE, | |
1676 base::Bind(&ContentSettingImageViewGtk::CloseAnimation, | |
1677 weak_factory_.GetWeakPtr()), | |
1678 base::TimeDelta::FromMilliseconds(kContentSettingImageDisplayTime)); | |
1679 } else { | |
1680 gtk_widget_hide(label_.get()); | |
1681 gtk_util::StopActingAsRoundedWindow(event_box_.get()); | |
1682 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); | |
1683 } | |
1684 } | |
1685 | |
1686 GdkColor LocationBarViewGtk::ContentSettingImageViewGtk:: | |
1687 button_border_color() const { | |
1688 return kContentSettingBorderColor; | |
1689 } | |
1690 | |
1691 GdkColor LocationBarViewGtk::ContentSettingImageViewGtk:: | |
1692 gradient_top_color() const { | |
1693 return kContentSettingTopColor; | |
1694 } | |
1695 | |
1696 GdkColor LocationBarViewGtk::ContentSettingImageViewGtk:: | |
1697 gradient_bottom_color() const { | |
1698 return kContentSettingBottomColor; | |
1699 } | |
1700 | |
1701 void LocationBarViewGtk::ContentSettingImageViewGtk::OnClick( | |
1702 GtkWidget* sender) { | |
1703 TabContents* tab_contents = parent_->GetTabContents(); | |
1704 if (!tab_contents) | |
1705 return; | |
1706 Profile* profile = parent_->browser()->profile(); | |
1707 content_setting_bubble_ = new ContentSettingBubbleGtk( | |
1708 sender, this, | |
1709 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | |
1710 parent_->browser()->content_setting_bubble_model_delegate(), | |
1711 tab_contents, | |
1712 profile, | |
1713 content_setting_image_model_->get_content_settings_type()), | |
1714 profile, tab_contents->web_contents()); | |
1715 return; | |
1716 } | |
1717 | |
1610 void LocationBarViewGtk::ContentSettingImageViewGtk::BubbleClosing( | 1718 void LocationBarViewGtk::ContentSettingImageViewGtk::BubbleClosing( |
1611 BubbleGtk* bubble, | 1719 BubbleGtk* bubble, |
1612 bool closed_by_escape) { | 1720 bool closed_by_escape) { |
1613 content_setting_bubble_ = NULL; | 1721 content_setting_bubble_ = NULL; |
1614 } | 1722 } |
1615 | 1723 |
1616 //////////////////////////////////////////////////////////////////////////////// | 1724 //////////////////////////////////////////////////////////////////////////////// |
1617 // LocationBarViewGtk::PageActionViewGtk | 1725 // LocationBarViewGtk::PageActionViewGtk |
1618 | 1726 |
1619 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( | 1727 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1972 } | 2080 } |
1973 | 2081 |
1974 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( | 2082 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
1975 ExtensionAction* action) { | 2083 ExtensionAction* action) { |
1976 ExtensionPopupGtk::Show( | 2084 ExtensionPopupGtk::Show( |
1977 action->GetPopupUrl(current_tab_id_), | 2085 action->GetPopupUrl(current_tab_id_), |
1978 owner_->browser_, | 2086 owner_->browser_, |
1979 event_box_.get(), | 2087 event_box_.get(), |
1980 ExtensionPopupGtk::SHOW_AND_INSPECT); | 2088 ExtensionPopupGtk::SHOW_AND_INSPECT); |
1981 } | 2089 } |
OLD | NEW |