summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-28 19:47:13 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-28 19:47:13 +0000
commited9e205c089ed4c8982370ca502efcc2dbc26a44 (patch)
treef8692e8d27a117be0ae3f61ee5969968ae4538be
parent7c2a34b9ef9eab5c58518d43e32f68cdf6e2289a (diff)
downloadchromium_src-ed9e205c089ed4c8982370ca502efcc2dbc26a44.zip
chromium_src-ed9e205c089ed4c8982370ca502efcc2dbc26a44.tar.gz
chromium_src-ed9e205c089ed4c8982370ca502efcc2dbc26a44.tar.bz2
GTK: Add a drag icon for site icon drags.
BUG=42147 TEST=manual Review URL: http://codereview.chromium.org/1725011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45846 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc63
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h5
2 files changed, 61 insertions, 7 deletions
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 18eda70..c9adf88 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -46,6 +46,7 @@
#include "chrome/common/page_transition_types.h"
#include "chrome/common/pref_names.h"
#include "gfx/canvas_paint.h"
+#include "gfx/font.h"
#include "gfx/gtk_util.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -91,6 +92,9 @@ const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75);
// Size of the rounding of the "Search site for:" box.
const int kCornerSize = 3;
+// Space between the favicon and the title when dragging the location icon.
+const int kFavIconTitleSpacing = 4;
+
// Returns the short name for a keyword.
std::wstring GetKeywordName(Profile* profile,
const std::wstring& keyword) {
@@ -177,6 +181,7 @@ LocationBarViewGtk::~LocationBarViewGtk() {
// All of our widgets should have be children of / owned by the alignment.
star_.Destroy();
hbox_.Destroy();
+ drag_icon_.Destroy();
content_setting_hbox_.Destroy();
page_action_hbox_.Destroy();
}
@@ -383,7 +388,8 @@ void LocationBarViewGtk::BuildSiteTypeArea() {
gtk_box_pack_start(GTK_BOX(hbox_.get()), site_type_alignment_,
FALSE, FALSE, 0);
- // Set up drags.
+ g_signal_connect(site_type_event_box_, "button-release-event",
+ G_CALLBACK(&OnIconReleasedThunk), this);
}
void LocationBarViewGtk::SetSiteTypeDragSource() {
@@ -404,10 +410,22 @@ void LocationBarViewGtk::SetSiteTypeDragSource() {
gtk_dnd_util::TEXT_URI_LIST |
gtk_dnd_util::CHROME_NAMED_URL);
- g_signal_connect(site_type_event_box_, "button-release-event",
- G_CALLBACK(&OnIconReleasedThunk), this);
g_signal_connect(site_type_event_box_, "drag-data-get",
G_CALLBACK(&OnIconDragDataThunk), this);
+ g_signal_connect(site_type_event_box_, "drag-begin",
+ G_CALLBACK(&OnIconDragBeginThunk), this);
+
+ drag_icon_.Own(gtk_window_new(GTK_WINDOW_POPUP));
+ g_signal_connect(drag_icon_.get(), "expose-event",
+ G_CALLBACK(OnDragIconExposeThunk), this);
+ GdkScreen* screen = gtk_widget_get_screen(drag_icon_.get());
+ GdkColormap* rgba = gdk_screen_get_rgba_colormap(screen);
+ if (rgba)
+ gtk_widget_set_colormap(drag_icon_.get(), rgba);
+
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
+ gtk_widget_set_size_request(drag_icon_.get(), 200, base_font.height());
}
void LocationBarViewGtk::SetProfile(Profile* profile) {
@@ -556,13 +574,11 @@ void LocationBarViewGtk::OnSetFocus() {
}
SkBitmap LocationBarViewGtk::GetFavIcon() const {
- NOTIMPLEMENTED();
- return SkBitmap();
+ return GetTabContents()->GetFavIcon();
}
std::wstring LocationBarViewGtk::GetTitle() const {
- NOTIMPLEMENTED();
- return std::wstring();
+ return UTF16ToWideHack(GetTabContents()->GetTitle());
}
void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) {
@@ -968,6 +984,39 @@ void LocationBarViewGtk::OnIconDragData(GtkWidget* sender,
gtk_dnd_util::WriteURLWithName(data, tab->GetURL(), tab->GetTitle(), info);
}
+void LocationBarViewGtk::OnIconDragBegin(GtkWidget* sender,
+ GdkDragContext* context) {
+ if (gtk_util::IsScreenComposited())
+ gtk_drag_set_icon_widget(context, drag_icon_.get(), 0, 0);
+}
+
+gboolean LocationBarViewGtk::OnDragIconExpose(GtkWidget* sender,
+ GdkEventExpose* event) {
+ // Clear the background.
+ cairo_t* cr = gdk_cairo_create(event->window);
+ gdk_cairo_rectangle(cr, &event->area);
+ cairo_clip(cr);
+ cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
+ cairo_paint(cr);
+ cairo_destroy(cr);
+
+ // Paint the favicon.
+ gfx::CanvasPaint canvas(event, false);
+ SkBitmap icon = GetFavIcon();
+ canvas.DrawBitmapInt(icon, 0, 0);
+
+ // Paint the title text.
+ int text_x = icon.width() + kFavIconTitleSpacing;
+ int text_width = sender->allocation.width - text_x;
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
+ canvas.DrawStringInt(GetTitle(),
+ base_font, SK_ColorBLACK,
+ text_x, 0, text_width, sender->allocation.height);
+
+ return TRUE;
+}
+
void LocationBarViewGtk::OnEntryBoxSizeAllocate(GtkWidget* sender,
GtkAllocation* allocation) {
if (entry_box_width_ != allocation->width) {
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index fe9d26c..baa7e4a 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -278,6 +278,10 @@ class LocationBarViewGtk : public AutocompleteEditController,
GdkEventButton*);
CHROMEGTK_CALLBACK_4(LocationBarViewGtk, void, OnIconDragData,
GdkDragContext*, GtkSelectionData*, guint, guint);
+ CHROMEGTK_CALLBACK_1(LocationBarViewGtk, void, OnIconDragBegin,
+ GdkDragContext*);
+ CHROMEGTK_CALLBACK_1(LocationBarViewGtk, gboolean, OnDragIconExpose,
+ GdkEventExpose*);
CHROMEGTK_CALLBACK_1(LocationBarViewGtk, void, OnEntryBoxSizeAllocate,
GtkAllocation*);
CHROMEGTK_CALLBACK_1(LocationBarViewGtk, gboolean, OnStarButtonPress,
@@ -333,6 +337,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
GtkWidget* site_type_alignment_;
GtkWidget* site_type_event_box_;
GtkWidget* location_icon_image_;
+ OwnedWidgetGtk drag_icon_;
bool enable_location_drag_;
// TODO(pkasting): Split this label off and move the rest of the items to the
// left of the address bar.