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

Unified Diff: chrome/browser/gtk/location_bar_view_gtk.cc

Issue 1725011: GTK: Add a drag icon for site icon drags. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 8 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
« no previous file with comments | « chrome/browser/gtk/location_bar_view_gtk.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/gtk/location_bar_view_gtk.cc
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 18eda709aee41b05d4b2e57f4198299becdcf025..c9adf88f3cc753b205cb725f9a4e496f45522b81 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.
Elliot Glaysher 2010/04/28 00:31:09 We can't do this with cairo? Tears.
Evan Stade 2010/04/28 00:33:51 well, this does use cairo underneath, but using ca
+ 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) {
« no previous file with comments | « chrome/browser/gtk/location_bar_view_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698