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

Unified 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: Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
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 3859e58e77db904c69a158ac2105a184a542a282..b704ededeb4c579428fafbe60423b0710a810b72 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
@@ -60,6 +60,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"
@@ -141,6 +142,7 @@ 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);
@@ -152,6 +154,14 @@ const double kContentSettingBottomColor[] = { 0xff / 255.0,
0xe6 / 255.0,
0xaf / 255.0 };
+const GdkColor kContentSettingGrayColor = GDK_COLOR_RGB(0xa0, 0xa0, 0xa0);
+const double kContentSettingTopColorGray[] = { 0xe5 / 255.0,
+ 0xe5 / 255.0,
+ 0xe5 / 255.0 };
+const double kContentSettingBottomColorGray[] = { 0xd0 / 255.0,
+ 0xd0 / 255.0,
+ 0xd0 / 255.0 };
+
// If widget is visible, increment the int pointed to by count.
// Suitible for use with gtk_container_foreach.
void CountVisibleWidgets(GtkWidget* widget, gpointer count) {
@@ -179,6 +189,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),
@@ -211,6 +222,7 @@ LocationBarViewGtk::~LocationBarViewGtk() {
hbox_.Destroy();
content_setting_hbox_.Destroy();
page_action_hbox_.Destroy();
+ web_intents_hbox_.Destroy();
}
void LocationBarViewGtk::Init(bool popup_window_mode) {
@@ -366,6 +378,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_|.
@@ -497,6 +517,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()) {
@@ -780,6 +801,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);
}
@@ -922,6 +949,7 @@ void LocationBarViewGtk::Observe(int type,
UpdateChromeToMobileIcon();
UpdateSiteTypeArea();
UpdateContentSettingsIcons();
+ UpdateWebIntentsTool();
break;
}
@@ -1414,6 +1442,155 @@ void LocationBarViewGtk::AdjustChildrenVisibility() {
}
////////////////////////////////////////////////////////////////////////////////
+// LocationBarViewGtk::PageToolViewGtk
+
+LocationBarViewGtk::PageToolViewGtk::PageToolViewGtk(
+ const LocationBarViewGtk* parent)
+ : 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),
+ animation_(this),
+ weak_factory_(this) {
+ gtk_alignment_set_padding(GTK_ALIGNMENT(alignment_.get()), 1, 1, 0, 0);
+ gtk_container_add(GTK_CONTAINER(alignment_.get()), event_box_.get());
+
+ // Make the event box not visible so it does not paint a background.
+ gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE);
+ g_signal_connect(event_box_.get(), "button-press-event",
+ G_CALLBACK(&OnButtonPressedThunk), this);
+ g_signal_connect(event_box_.get(), "expose-event",
+ G_CALLBACK(&OnExposeThunk), this);
+
+ gtk_widget_set_no_show_all(label_.get(), TRUE);
+ gtk_label_set_line_wrap(GTK_LABEL(label_.get()), FALSE);
+
+ gtk_box_pack_start(GTK_BOX(hbox_), image_.get(), FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(hbox_), label_.get(), FALSE, FALSE, 0);
+
+ gtk_container_set_border_width(GTK_CONTAINER(hbox_), kHboxBorder);
+
+ gtk_container_add(GTK_CONTAINER(event_box_.get()), hbox_);
+ gtk_widget_hide(widget());
+
+ animation_.SetSlideDuration(kPageToolAnimationTime);
+}
+
+LocationBarViewGtk::PageToolViewGtk::~PageToolViewGtk() {
+ image_.Destroy();
+ label_.Destroy();
+ event_box_.Destroy();
+ alignment_.Destroy();
+}
+
+GtkWidget* LocationBarViewGtk::PageToolViewGtk::widget() {
+ return alignment_.get();
+}
+
+bool LocationBarViewGtk::PageToolViewGtk::IsVisible() {
+ return gtk_widget_get_visible(widget());
+}
+
+void LocationBarViewGtk::PageToolViewGtk::Update(
+ TabContents* tab_contents) {
+ if (!tab_contents ||
+ !tab_contents->web_intent_picker_controller() ||
+ !tab_contents->web_intent_picker_controller()->
+ ShowLocationBarPickerTool()) {
+ gtk_widget_hide(widget());
+ return;
+ }
+
+ gtk_widget_set_tooltip_text(widget(),
+ l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str());
+ gtk_widget_show_all(widget());
+
+ gtk_label_set_text(GTK_LABEL(label_.get()),
+ l10n_util::GetStringUTF8(IDS_INTENT_PICKER_USE_ANOTHER_SERVICE).c_str());
+
+ StartAnimating();
+}
+
+void LocationBarViewGtk::PageToolViewGtk::StartAnimating() {
+ if (animation_.IsShowing() || animation_.IsClosing())
+ return;
+
+ gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), TRUE);
+ GdkColor border_color = kContentSettingGrayColor;
+ gtk_util::ActAsRoundedWindow(event_box_.get(), border_color,
+ kCornerSize,
+ gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL);
+
+ gtk_widget_set_size_request(label_.get(), -1, -1);
+ gtk_widget_size_request(label_.get(), &label_req_);
+ gtk_widget_set_size_request(label_.get(), 0, -1);
+ gtk_widget_show(label_.get());
+
+ animation_.Show();
+}
+
+void LocationBarViewGtk::PageToolViewGtk::AnimationProgressed(
+ const ui::Animation* animation) {
+ gtk_widget_set_size_request(
+ label_.get(),
+ animation->GetCurrentValue() * label_req_.width,
+ -1);
+}
+
+void LocationBarViewGtk::PageToolViewGtk::AnimationCanceled(
+ const ui::Animation* animation) {
+}
+
+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);
+ }
+}
+
+gboolean LocationBarViewGtk::PageToolViewGtk::OnButtonPressed(
+ GtkWidget* sender, GdkEvent* event) {
+ LOG(INFO) << "CLICK!!!";
Bernhard Bauer 2012/07/24 20:37:03 ? :)
+ return TRUE;
+}
+
+gboolean LocationBarViewGtk::PageToolViewGtk::OnExpose(
+ GtkWidget* sender, GdkEventExpose* event) {
+ TRACE_EVENT0("ui::gtk", "LocationBarViewGtk::PageToolViewGtk::OnExpose");
+
+ if (!(animation_.IsShowing() || animation_.IsClosing()))
+ return FALSE;
+
+ GtkAllocation allocation;
+ gtk_widget_get_allocation(sender, &allocation);
+ const int height = allocation.height;
+
+ cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(sender));
+ gdk_cairo_rectangle(cr, &event->area);
+ cairo_clip(cr);
+
+ cairo_pattern_t* pattern = cairo_pattern_create_linear(0, 0, 0, height);
+
+ const double* top_color = kContentSettingTopColorGray;
+ const double* bottom_color = kContentSettingBottomColorGray;
+ cairo_pattern_add_color_stop_rgb(
+ pattern, 0.0, top_color[0], top_color[1], top_color[2]);
+ cairo_pattern_add_color_stop_rgb(
+ pattern, 1.0, bottom_color[0], bottom_color[1], bottom_color[2]);
+
+ cairo_set_source(cr, pattern);
+ cairo_paint(cr);
+ cairo_pattern_destroy(pattern);
+ cairo_destroy(cr);
+
+ return FALSE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
// LocationBarViewGtk::ContentSettingImageViewGtk
LocationBarViewGtk::ContentSettingImageViewGtk::ContentSettingImageViewGtk(
ContentSettingsType content_type,
@@ -1514,7 +1691,8 @@ void LocationBarViewGtk::ContentSettingImageViewGtk::StartAnimating() {
return;
gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), TRUE);
- gtk_util::ActAsRoundedWindow(event_box_.get(), kContentSettingBorderColor,
+ GdkColor border_color = kContentSettingBorderColor;
+ gtk_util::ActAsRoundedWindow(event_box_.get(), border_color,
kCornerSize,
gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL);
@@ -1592,14 +1770,13 @@ 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 double* top_color = kContentSettingTopColor;
+ const double* bottom_color = kContentSettingBottomColor;
+ cairo_pattern_add_color_stop_rgb(
+ pattern, 0.0, top_color[0], top_color[1], top_color[2]);
+ cairo_pattern_add_color_stop_rgb(
+ pattern, 1.0, bottom_color[0], bottom_color[1], bottom_color[2]);
+
cairo_set_source(cr, pattern);
cairo_paint(cr);
cairo_pattern_destroy(pattern);

Powered by Google App Engine
This is Rietveld 408576698