Chromium Code Reviews| Index: chrome/browser/ui/gtk/location_bar_view_gtk.cc |
| diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc |
| index fe576e2832db1407f27c130a6f0652fb97778774..06f6e308138e203c0116f2bddddfa116b4f738cc 100644 |
| --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc |
| +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc |
| @@ -59,6 +59,7 @@ |
| #include "chrome/browser/ui/gtk/rounded_window.h" |
| #include "chrome/browser/ui/gtk/view_id_util.h" |
| #include "chrome/browser/ui/gtk/zoom_bubble_gtk.h" |
| +#include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
| #include "chrome/browser/ui/omnibox/location_bar_util.h" |
| #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| @@ -140,16 +141,17 @@ const int kCornerSize = 3; |
| const int kContentSettingImageDisplayTime = 3200; |
| // The time, in ms, of the animation (open and close). |
| const int kContentSettingImageAnimationTime = 150; |
| +const int kPageToolAnimationTime = 1000; |
| // Color of border of content setting area (icon/label). |
| const GdkColor kContentSettingBorderColor = GDK_COLOR_RGB(0xe9, 0xb9, 0x66); |
| // Colors for the background gradient. |
| -const double kContentSettingTopColor[] = { 0xff / 255.0, |
| - 0xf8 / 255.0, |
| - 0xd4 / 255.0 }; |
| -const double kContentSettingBottomColor[] = { 0xff / 255.0, |
| - 0xe6 / 255.0, |
| - 0xaf / 255.0 }; |
| +const GdkColor kContentSettingTopColor = GDK_COLOR_RGB(0xff, 0xf8, 0xd4); |
| +const GdkColor kContentSettingBottomColor = GDK_COLOR_RGB(0xff, 0xe6, 0xaf); |
| + |
| +const GdkColor kGrayBorderColor = GDK_COLOR_RGB(0xa0, 0xa0, 0xa0); |
| +const GdkColor kTopColorGray = GDK_COLOR_RGB(0xe5, 0xe5, 0xe5); |
| +const GdkColor kBottomColorGray = GDK_COLOR_RGB(0xd0, 0xd0, 0xd0); |
| // If widget is visible, increment the int pointed to by count. |
| // Suitible for use with gtk_container_foreach. |
| @@ -178,6 +180,7 @@ LocationBarViewGtk::LocationBarViewGtk(Browser* browser) |
| drag_icon_(NULL), |
| enable_location_drag_(false), |
| security_info_label_(NULL), |
| + web_intents_tool_view_(this), |
| tab_to_search_alignment_(NULL), |
| tab_to_search_box_(NULL), |
| tab_to_search_full_label_(NULL), |
| @@ -210,6 +213,7 @@ LocationBarViewGtk::~LocationBarViewGtk() { |
| hbox_.Destroy(); |
| content_setting_hbox_.Destroy(); |
| page_action_hbox_.Destroy(); |
| + web_intents_hbox_.Destroy(); |
| } |
| void LocationBarViewGtk::Init(bool popup_window_mode) { |
| @@ -365,6 +369,14 @@ void LocationBarViewGtk::Init(bool popup_window_mode) { |
| gtk_box_pack_end(GTK_BOX(hbox_.get()), page_action_hbox_.get(), |
| FALSE, FALSE, 0); |
| + web_intents_hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); |
| + gtk_widget_set_name(web_intents_hbox_.get(), |
| + "chrome-web-intents-hbox"); |
| + gtk_box_pack_end(GTK_BOX(hbox_.get()), web_intents_hbox_.get(), |
| + FALSE, FALSE, 0); |
| + gtk_box_pack_end(GTK_BOX(web_intents_hbox_.get()), |
| + web_intents_tool_view_.widget(), FALSE, FALSE, 0); |
| + |
| // Now that we've created the widget hierarchy, connect to the main |hbox_|'s |
| // size-allocate so we can do proper resizing and eliding on |
| // |security_info_label_|. |
| @@ -496,6 +508,7 @@ void LocationBarViewGtk::Update(const WebContents* contents) { |
| UpdateSiteTypeArea(); |
| UpdateContentSettingsIcons(); |
| UpdatePageActions(); |
| + UpdateWebIntentsTool(); |
| location_entry_->Update(contents); |
| // The security level (background color) could have changed, etc. |
| if (theme_service_->UsingNativeTheme()) { |
| @@ -709,13 +722,12 @@ void LocationBarViewGtk::FocusSearch() { |
| } |
| void LocationBarViewGtk::UpdateContentSettingsIcons() { |
| - WebContents* web_contents = GetWebContents(); |
| bool any_visible = false; |
| for (ScopedVector<ContentSettingImageViewGtk>::iterator i( |
| content_setting_views_.begin()); |
| i != content_setting_views_.end(); ++i) { |
| - (*i)->UpdateFromWebContents( |
| - toolbar_model_->input_in_progress() ? NULL : web_contents); |
| + (*i)->Update( |
| + toolbar_model_->input_in_progress() ? NULL : GetTabContents()); |
| any_visible = (*i)->IsVisible() || any_visible; |
| } |
| @@ -779,6 +791,12 @@ void LocationBarViewGtk::InvalidatePageActions() { |
| } |
| } |
| +void LocationBarViewGtk::UpdateWebIntentsTool() { |
| + web_intents_tool_view_.Update(GetTabContents()); |
| + gtk_widget_set_visible(web_intents_hbox_.get(), |
| + web_intents_tool_view_.IsVisible()); |
| +} |
| + |
| void LocationBarViewGtk::SaveStateToContents(WebContents* contents) { |
| location_entry_->SaveStateToTab(contents); |
| } |
| @@ -921,6 +939,7 @@ void LocationBarViewGtk::Observe(int type, |
| UpdateChromeToMobileIcon(); |
| UpdateSiteTypeArea(); |
| UpdateContentSettingsIcons(); |
| + UpdateWebIntentsTool(); |
| break; |
| } |
| @@ -1413,20 +1432,16 @@ void LocationBarViewGtk::AdjustChildrenVisibility() { |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| -// LocationBarViewGtk::ContentSettingImageViewGtk |
| -LocationBarViewGtk::ContentSettingImageViewGtk::ContentSettingImageViewGtk( |
| - ContentSettingsType content_type, |
| +// LocationBarViewGtk::PageToolViewGtk |
| + |
| +LocationBarViewGtk::PageToolViewGtk::PageToolViewGtk( |
| const LocationBarViewGtk* parent) |
| - : content_setting_image_model_( |
| - ContentSettingImageModel::CreateContentSettingImageModel( |
| - content_type)), |
| - alignment_(gtk_alignment_new(0, 0, 1, 1)), |
| + : alignment_(gtk_alignment_new(0, 0, 1, 1)), |
| event_box_(gtk_event_box_new()), |
| hbox_(gtk_hbox_new(FALSE, kInnerPadding)), |
| image_(gtk_image_new()), |
| label_(gtk_label_new(NULL)), |
| parent_(parent), |
| - content_setting_bubble_(NULL), |
| animation_(this), |
| weak_factory_(this) { |
| gtk_alignment_set_padding(GTK_ALIGNMENT(alignment_.get()), 1, 1, 0, 0); |
| @@ -1450,70 +1465,55 @@ LocationBarViewGtk::ContentSettingImageViewGtk::ContentSettingImageViewGtk( |
| gtk_container_add(GTK_CONTAINER(event_box_.get()), hbox_); |
| gtk_widget_hide(widget()); |
| - animation_.SetSlideDuration(kContentSettingImageAnimationTime); |
| + animation_.SetSlideDuration(kPageToolAnimationTime); |
| } |
| -LocationBarViewGtk::ContentSettingImageViewGtk::~ContentSettingImageViewGtk() { |
| +LocationBarViewGtk::PageToolViewGtk::~PageToolViewGtk() { |
| image_.Destroy(); |
| label_.Destroy(); |
| event_box_.Destroy(); |
| alignment_.Destroy(); |
| +} |
| - if (content_setting_bubble_) |
| - content_setting_bubble_->Close(); |
| +GtkWidget* LocationBarViewGtk::PageToolViewGtk::widget() { |
| + return alignment_.get(); |
| } |
| -bool LocationBarViewGtk::ContentSettingImageViewGtk::IsVisible() { |
| +bool LocationBarViewGtk::PageToolViewGtk::IsVisible() { |
| return gtk_widget_get_visible(widget()); |
| } |
| -void LocationBarViewGtk::ContentSettingImageViewGtk::UpdateFromWebContents( |
| - WebContents* web_contents) { |
| - content_setting_image_model_->UpdateFromWebContents(web_contents); |
| - if (!content_setting_image_model_->is_visible()) { |
| +void LocationBarViewGtk::PageToolViewGtk::Update( |
|
Bernhard Bauer
2012/07/27 00:35:38
Where is this method called?
|
| + TabContents* tab_contents) { |
| + if (!tab_contents || |
| + !tab_contents->web_intent_picker_controller() || |
|
Bernhard Bauer
2012/07/27 00:35:38
This still seems to be Web Intents specific?
|
| + !tab_contents->web_intent_picker_controller()-> |
| + ShowLocationBarPickerTool()) { |
| gtk_widget_hide(widget()); |
| return; |
| } |
| - gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), |
| - GtkThemeService::GetFrom(parent_->browser()->profile())->GetImageNamed( |
| - content_setting_image_model_->get_icon())->ToGdkPixbuf()); |
| - |
| gtk_widget_set_tooltip_text(widget(), |
| - content_setting_image_model_->get_tooltip().c_str()); |
| + l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str()); |
| gtk_widget_show_all(widget()); |
| - TabSpecificContentSettings* content_settings = NULL; |
| - if (web_contents) { |
| - content_settings = |
| - TabContents::FromWebContents(web_contents)->content_settings(); |
| - } |
| - if (!content_settings || content_settings->IsBlockageIndicated( |
| - content_setting_image_model_->get_content_settings_type())) |
| - return; |
| - |
| - // The content blockage was not yet indicated to the user. Start indication |
| - // animation and clear "not yet shown" flag. |
| - content_settings->SetBlockageHasBeenIndicated( |
| - content_setting_image_model_->get_content_settings_type()); |
| - |
| - int label_string_id = |
| - content_setting_image_model_->explanatory_string_id(); |
| - // If there's no string for the content type, we don't animate. |
| - if (!label_string_id) |
| - return; |
| - |
| gtk_label_set_text(GTK_LABEL(label_.get()), |
| - l10n_util::GetStringUTF8(label_string_id).c_str()); |
| + l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str()); |
| + |
| StartAnimating(); |
| } |
| -void LocationBarViewGtk::ContentSettingImageViewGtk::StartAnimating() { |
| +GdkColor LocationBarViewGtk::PageToolViewGtk::button_border_color() const { |
| + return kGrayBorderColor; |
| +} |
| + |
| +void LocationBarViewGtk::PageToolViewGtk::StartAnimating() { |
| if (animation_.IsShowing() || animation_.IsClosing()) |
| return; |
| gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), TRUE); |
| - gtk_util::ActAsRoundedWindow(event_box_.get(), kContentSettingBorderColor, |
| + GdkColor border_color = button_border_color(); |
| + gtk_util::ActAsRoundedWindow(event_box_.get(), border_color, |
| kCornerSize, |
| gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL); |
| @@ -1525,11 +1525,11 @@ void LocationBarViewGtk::ContentSettingImageViewGtk::StartAnimating() { |
| animation_.Show(); |
| } |
| -void LocationBarViewGtk::ContentSettingImageViewGtk::CloseAnimation() { |
| +void LocationBarViewGtk::PageToolViewGtk::CloseAnimation() { |
| animation_.Hide(); |
| } |
| -void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationProgressed( |
| +void LocationBarViewGtk::PageToolViewGtk::AnimationProgressed( |
| const ui::Animation* animation) { |
| gtk_widget_set_size_request( |
| label_.get(), |
| @@ -1537,46 +1537,40 @@ void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationProgressed( |
| -1); |
| } |
| -void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationEnded( |
| +void LocationBarViewGtk::PageToolViewGtk::AnimationCanceled( |
| const ui::Animation* animation) { |
| - if (animation_.IsShowing()) { |
| - MessageLoop::current()->PostDelayedTask( |
| - FROM_HERE, |
| - base::Bind(&ContentSettingImageViewGtk::CloseAnimation, |
| - weak_factory_.GetWeakPtr()), |
| - base::TimeDelta::FromMilliseconds(kContentSettingImageDisplayTime)); |
| - } else { |
| +} |
| + |
| +void LocationBarViewGtk::PageToolViewGtk::AnimationEnded( |
| + const ui::Animation* animation) { |
| + if (!animation_.IsShowing()) { |
| gtk_widget_hide(label_.get()); |
| gtk_util::StopActingAsRoundedWindow(event_box_.get()); |
| gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
| } |
| } |
| -void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationCanceled( |
| - const ui::Animation* animation) { |
| -} |
| - |
| -gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnButtonPressed( |
| +gboolean LocationBarViewGtk::PageToolViewGtk::OnButtonPressed( |
| GtkWidget* sender, GdkEvent* event) { |
| - TabContents* tab_contents = parent_->GetTabContents(); |
| - if (!tab_contents) |
| - return TRUE; |
| - Profile* profile = parent_->browser()->profile(); |
| - content_setting_bubble_ = new ContentSettingBubbleGtk( |
| - sender, this, |
| - ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| - parent_->browser()->content_setting_bubble_model_delegate(), |
| - tab_contents, |
| - profile, |
| - content_setting_image_model_->get_content_settings_type()), |
| - profile, tab_contents->web_contents()); |
| + OnClick(sender); |
| return TRUE; |
| } |
| -gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnExpose( |
| +void LocationBarViewGtk::PageToolViewGtk::OnClick(GtkWidget* sender) { |
| + LOG(INFO) << "CLICK!!!"; |
| +} |
| + |
| +GdkColor LocationBarViewGtk::PageToolViewGtk::gradient_top_color() const { |
| + return kTopColorGray; |
| +} |
| + |
| +GdkColor LocationBarViewGtk::PageToolViewGtk::gradient_bottom_color() const { |
| + return kBottomColorGray; |
| +} |
| + |
| +gboolean LocationBarViewGtk::PageToolViewGtk::OnExpose( |
| GtkWidget* sender, GdkEventExpose* event) { |
| - TRACE_EVENT0("ui::gtk", |
| - "LocationBarViewGtk::ContentSettingImageViewGtk::OnExpose"); |
| + TRACE_EVENT0("ui::gtk", "LocationBarViewGtk::PageToolViewGtk::OnExpose"); |
| if (!(animation_.IsShowing() || animation_.IsClosing())) |
| return FALSE; |
| @@ -1591,14 +1585,19 @@ gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnExpose( |
| cairo_pattern_t* pattern = cairo_pattern_create_linear(0, 0, 0, height); |
| - cairo_pattern_add_color_stop_rgb(pattern, 0.0, |
| - kContentSettingTopColor[0], |
| - kContentSettingTopColor[1], |
| - kContentSettingTopColor[2]); |
| - cairo_pattern_add_color_stop_rgb(pattern, 1.0, |
| - kContentSettingBottomColor[0], |
| - kContentSettingBottomColor[1], |
| - kContentSettingBottomColor[2]); |
| + const GdkColor top_color = gradient_top_color(); |
| + const GdkColor bottom_color = gradient_bottom_color(); |
| + cairo_pattern_add_color_stop_rgb( |
| + pattern, 0.0, |
| + top_color.red/255.0, |
| + top_color.blue/255.0, |
| + top_color.green/255.0); |
| + cairo_pattern_add_color_stop_rgb( |
| + pattern, 1.0, |
| + bottom_color.red/255.0, |
| + bottom_color.blue/255.0, |
| + bottom_color.green/255.0); |
| + |
| cairo_set_source(cr, pattern); |
| cairo_paint(cr); |
| cairo_pattern_destroy(pattern); |
| @@ -1607,6 +1606,115 @@ gboolean LocationBarViewGtk::ContentSettingImageViewGtk::OnExpose( |
| return FALSE; |
| } |
| +//////////////////////////////////////////////////////////////////////////////// |
| +// LocationBarViewGtk::ContentSettingImageViewGtk |
| +LocationBarViewGtk::ContentSettingImageViewGtk::ContentSettingImageViewGtk( |
| + ContentSettingsType content_type, |
| + const LocationBarViewGtk* parent) |
| + : PageToolViewGtk(parent), |
| + content_setting_image_model_( |
| + ContentSettingImageModel::CreateContentSettingImageModel( |
| + content_type)), |
| + content_setting_bubble_(NULL) { |
| + animation_.SetSlideDuration(kContentSettingImageAnimationTime); |
| +} |
| + |
| +LocationBarViewGtk::ContentSettingImageViewGtk::~ContentSettingImageViewGtk() { |
| + if (content_setting_bubble_) |
| + content_setting_bubble_->Close(); |
| +} |
| + |
| +void LocationBarViewGtk::ContentSettingImageViewGtk::Update( |
| + TabContents* tab_contents) { |
| + if (tab_contents) { |
| + content_setting_image_model_->UpdateFromWebContents( |
| + tab_contents->web_contents()); |
| + } |
| + if (!content_setting_image_model_->is_visible()) { |
| + gtk_widget_hide(widget()); |
| + return; |
| + } |
| + |
| + gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), |
| + GtkThemeService::GetFrom(parent_->browser()->profile())->GetImageNamed( |
| + content_setting_image_model_->get_icon())->ToGdkPixbuf()); |
| + |
| + gtk_widget_set_tooltip_text(widget(), |
| + content_setting_image_model_->get_tooltip().c_str()); |
| + gtk_widget_show_all(widget()); |
| + |
| + if (!tab_contents) |
| + return; |
| + |
| + TabSpecificContentSettings* content_settings = |
| + tab_contents->content_settings(); |
| + if (!content_settings || content_settings->IsBlockageIndicated( |
| + content_setting_image_model_->get_content_settings_type())) |
| + return; |
| + |
| + // The content blockage was not yet indicated to the user. Start indication |
| + // animation and clear "not yet shown" flag. |
| + content_settings->SetBlockageHasBeenIndicated( |
| + content_setting_image_model_->get_content_settings_type()); |
| + |
| + int label_string_id = |
| + content_setting_image_model_->explanatory_string_id(); |
| + // If there's no string for the content type, we don't animate. |
| + if (!label_string_id) |
| + return; |
| + |
| + gtk_label_set_text(GTK_LABEL(label_.get()), |
| + l10n_util::GetStringUTF8(label_string_id).c_str()); |
| + StartAnimating(); |
| +} |
| + |
| +void LocationBarViewGtk::ContentSettingImageViewGtk::AnimationEnded( |
| + const ui::Animation* animation) { |
| + if (animation_.IsShowing()) { |
| + MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&ContentSettingImageViewGtk::CloseAnimation, |
| + weak_factory_.GetWeakPtr()), |
| + base::TimeDelta::FromMilliseconds(kContentSettingImageDisplayTime)); |
| + } else { |
| + gtk_widget_hide(label_.get()); |
| + gtk_util::StopActingAsRoundedWindow(event_box_.get()); |
| + gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
| + } |
| +} |
| + |
| +GdkColor LocationBarViewGtk::ContentSettingImageViewGtk:: |
| + button_border_color() const { |
| + return kContentSettingBorderColor; |
| +} |
| + |
| +GdkColor LocationBarViewGtk::ContentSettingImageViewGtk:: |
| + gradient_top_color() const { |
| + return kContentSettingTopColor; |
| +} |
| + |
| +GdkColor LocationBarViewGtk::ContentSettingImageViewGtk:: |
| + gradient_bottom_color() const { |
| + return kContentSettingBottomColor; |
| +} |
| + |
| +void LocationBarViewGtk::ContentSettingImageViewGtk::OnClick( |
| + GtkWidget* sender) { |
| + TabContents* tab_contents = parent_->GetTabContents(); |
| + if (!tab_contents) |
| + return; |
| + Profile* profile = parent_->browser()->profile(); |
| + content_setting_bubble_ = new ContentSettingBubbleGtk( |
| + sender, this, |
| + ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| + parent_->browser()->content_setting_bubble_model_delegate(), |
| + tab_contents, |
| + profile, |
| + content_setting_image_model_->get_content_settings_type()), |
| + profile, tab_contents->web_contents()); |
| + return; |
| +} |
| + |
| void LocationBarViewGtk::ContentSettingImageViewGtk::BubbleClosing( |
| BubbleGtk* bubble, |
| bool closed_by_escape) { |