OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/gtk/location_bar_view_gtk.h" | 5 #include "chrome/browser/gtk/location_bar_view_gtk.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/gtk_dnd_util.h" | 9 #include "app/gtk_dnd_util.h" |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 28 matching lines...) Loading... | |
39 #include "chrome/browser/profile.h" | 39 #include "chrome/browser/profile.h" |
40 #include "chrome/browser/search_engines/template_url.h" | 40 #include "chrome/browser/search_engines/template_url.h" |
41 #include "chrome/browser/search_engines/template_url_model.h" | 41 #include "chrome/browser/search_engines/template_url_model.h" |
42 #include "chrome/browser/tab_contents/tab_contents.h" | 42 #include "chrome/browser/tab_contents/tab_contents.h" |
43 #include "chrome/common/extensions/extension.h" | 43 #include "chrome/common/extensions/extension.h" |
44 #include "chrome/common/extensions/extension_action.h" | 44 #include "chrome/common/extensions/extension_action.h" |
45 #include "chrome/common/notification_service.h" | 45 #include "chrome/common/notification_service.h" |
46 #include "chrome/common/page_transition_types.h" | 46 #include "chrome/common/page_transition_types.h" |
47 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
48 #include "gfx/canvas_paint.h" | 48 #include "gfx/canvas_paint.h" |
49 #include "gfx/font.h" | |
49 #include "gfx/gtk_util.h" | 50 #include "gfx/gtk_util.h" |
50 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
51 #include "grit/theme_resources.h" | 52 #include "grit/theme_resources.h" |
52 #include "net/base/net_util.h" | 53 #include "net/base/net_util.h" |
53 #include "webkit/glue/window_open_disposition.h" | 54 #include "webkit/glue/window_open_disposition.h" |
54 | 55 |
55 namespace { | 56 namespace { |
56 | 57 |
57 // We are positioned with a little bit of extra space that we don't use now. | 58 // We are positioned with a little bit of extra space that we don't use now. |
58 const int kTopMargin = 1; | 59 const int kTopMargin = 1; |
(...skipping 25 matching lines...) Loading... | |
84 // Colors used to draw the Tab to Search rounded bubble. | 85 // Colors used to draw the Tab to Search rounded bubble. |
85 const GdkColor kKeywordBackgroundColor = GDK_COLOR_RGB(0xf0, 0xf4, 0xfa); | 86 const GdkColor kKeywordBackgroundColor = GDK_COLOR_RGB(0xf0, 0xf4, 0xfa); |
86 const GdkColor kKeywordBorderColor = GDK_COLOR_RGB(0xcb, 0xde, 0xf7); | 87 const GdkColor kKeywordBorderColor = GDK_COLOR_RGB(0xcb, 0xde, 0xf7); |
87 | 88 |
88 // Use weak gray for showing search and keyword hint text. | 89 // Use weak gray for showing search and keyword hint text. |
89 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75); | 90 const GdkColor kHintTextColor = GDK_COLOR_RGB(0x75, 0x75, 0x75); |
90 | 91 |
91 // Size of the rounding of the "Search site for:" box. | 92 // Size of the rounding of the "Search site for:" box. |
92 const int kCornerSize = 3; | 93 const int kCornerSize = 3; |
93 | 94 |
95 // Space between the favicon and the title when dragging the location icon. | |
96 const int kFavIconTitleSpacing = 4; | |
97 | |
94 // Returns the short name for a keyword. | 98 // Returns the short name for a keyword. |
95 std::wstring GetKeywordName(Profile* profile, | 99 std::wstring GetKeywordName(Profile* profile, |
96 const std::wstring& keyword) { | 100 const std::wstring& keyword) { |
97 // Make sure the TemplateURL still exists. | 101 // Make sure the TemplateURL still exists. |
98 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel | 102 // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel |
99 // to track changes to the model, this should become a DCHECK. | 103 // to track changes to the model, this should become a DCHECK. |
100 const TemplateURL* template_url = | 104 const TemplateURL* template_url = |
101 profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); | 105 profile->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); |
102 if (template_url) | 106 if (template_url) |
103 return template_url->AdjustedShortNameForLocaleDirection(); | 107 return template_url->AdjustedShortNameForLocaleDirection(); |
(...skipping 66 matching lines...) Loading... | |
170 theme_provider_(NULL), | 174 theme_provider_(NULL), |
171 entry_box_width_(0), | 175 entry_box_width_(0), |
172 show_selected_keyword_(false), | 176 show_selected_keyword_(false), |
173 show_keyword_hint_(false) { | 177 show_keyword_hint_(false) { |
174 } | 178 } |
175 | 179 |
176 LocationBarViewGtk::~LocationBarViewGtk() { | 180 LocationBarViewGtk::~LocationBarViewGtk() { |
177 // All of our widgets should have be children of / owned by the alignment. | 181 // All of our widgets should have be children of / owned by the alignment. |
178 star_.Destroy(); | 182 star_.Destroy(); |
179 hbox_.Destroy(); | 183 hbox_.Destroy(); |
184 drag_icon_.Destroy(); | |
180 content_setting_hbox_.Destroy(); | 185 content_setting_hbox_.Destroy(); |
181 page_action_hbox_.Destroy(); | 186 page_action_hbox_.Destroy(); |
182 } | 187 } |
183 | 188 |
184 void LocationBarViewGtk::Init(bool popup_window_mode) { | 189 void LocationBarViewGtk::Init(bool popup_window_mode) { |
185 popup_window_mode_ = popup_window_mode; | 190 popup_window_mode_ = popup_window_mode; |
186 | 191 |
187 // Create the widget first, so we can pass it to the AutocompleteEditViewGtk. | 192 // Create the widget first, so we can pass it to the AutocompleteEditViewGtk. |
188 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); | 193 hbox_.Own(gtk_hbox_new(FALSE, kInnerPadding)); |
189 gtk_container_set_border_width(GTK_CONTAINER(hbox_.get()), kHboxBorder); | 194 gtk_container_set_border_width(GTK_CONTAINER(hbox_.get()), kHboxBorder); |
(...skipping 186 matching lines...) Loading... | |
376 | 381 |
377 // Put the event box in an alignment to get the padding correct. | 382 // Put the event box in an alignment to get the padding correct. |
378 site_type_alignment_ = gtk_alignment_new(0, 0, 1, 1); | 383 site_type_alignment_ = gtk_alignment_new(0, 0, 1, 1); |
379 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), | 384 gtk_alignment_set_padding(GTK_ALIGNMENT(site_type_alignment_), |
380 0, 0, 1, 0); | 385 0, 0, 1, 0); |
381 gtk_container_add(GTK_CONTAINER(site_type_alignment_), | 386 gtk_container_add(GTK_CONTAINER(site_type_alignment_), |
382 site_type_event_box_); | 387 site_type_event_box_); |
383 gtk_box_pack_start(GTK_BOX(hbox_.get()), site_type_alignment_, | 388 gtk_box_pack_start(GTK_BOX(hbox_.get()), site_type_alignment_, |
384 FALSE, FALSE, 0); | 389 FALSE, FALSE, 0); |
385 | 390 |
386 // Set up drags. | 391 g_signal_connect(site_type_event_box_, "button-release-event", |
392 G_CALLBACK(&OnIconReleasedThunk), this); | |
387 } | 393 } |
388 | 394 |
389 void LocationBarViewGtk::SetSiteTypeDragSource() { | 395 void LocationBarViewGtk::SetSiteTypeDragSource() { |
390 bool enable = !location_entry()->IsEditingOrEmpty(); | 396 bool enable = !location_entry()->IsEditingOrEmpty(); |
391 if (enable_location_drag_ == enable) | 397 if (enable_location_drag_ == enable) |
392 return; | 398 return; |
393 enable_location_drag_ = enable; | 399 enable_location_drag_ = enable; |
394 | 400 |
395 if (!enable) { | 401 if (!enable) { |
396 gtk_drag_source_unset(site_type_event_box_); | 402 gtk_drag_source_unset(site_type_event_box_); |
397 return; | 403 return; |
398 } | 404 } |
399 | 405 |
400 gtk_drag_source_set(site_type_event_box_, GDK_BUTTON1_MASK, | 406 gtk_drag_source_set(site_type_event_box_, GDK_BUTTON1_MASK, |
401 NULL, 0, GDK_ACTION_COPY); | 407 NULL, 0, GDK_ACTION_COPY); |
402 gtk_dnd_util::SetSourceTargetListFromCodeMask(site_type_event_box_, | 408 gtk_dnd_util::SetSourceTargetListFromCodeMask(site_type_event_box_, |
403 gtk_dnd_util::TEXT_PLAIN | | 409 gtk_dnd_util::TEXT_PLAIN | |
404 gtk_dnd_util::TEXT_URI_LIST | | 410 gtk_dnd_util::TEXT_URI_LIST | |
405 gtk_dnd_util::CHROME_NAMED_URL); | 411 gtk_dnd_util::CHROME_NAMED_URL); |
406 | 412 |
407 g_signal_connect(site_type_event_box_, "button-release-event", | |
408 G_CALLBACK(&OnIconReleasedThunk), this); | |
409 g_signal_connect(site_type_event_box_, "drag-data-get", | 413 g_signal_connect(site_type_event_box_, "drag-data-get", |
410 G_CALLBACK(&OnIconDragDataThunk), this); | 414 G_CALLBACK(&OnIconDragDataThunk), this); |
415 g_signal_connect(site_type_event_box_, "drag-begin", | |
416 G_CALLBACK(&OnIconDragBeginThunk), this); | |
417 | |
418 drag_icon_.Own(gtk_window_new(GTK_WINDOW_POPUP)); | |
419 g_signal_connect(drag_icon_.get(), "expose-event", | |
420 G_CALLBACK(OnDragIconExposeThunk), this); | |
421 GdkScreen* screen = gtk_widget_get_screen(drag_icon_.get()); | |
422 GdkColormap* rgba = gdk_screen_get_rgba_colormap(screen); | |
423 if (rgba) | |
424 gtk_widget_set_colormap(drag_icon_.get(), rgba); | |
425 | |
426 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
427 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | |
428 gtk_widget_set_size_request(drag_icon_.get(), 200, base_font.height()); | |
411 } | 429 } |
412 | 430 |
413 void LocationBarViewGtk::SetProfile(Profile* profile) { | 431 void LocationBarViewGtk::SetProfile(Profile* profile) { |
414 profile_ = profile; | 432 profile_ = profile; |
415 } | 433 } |
416 | 434 |
417 TabContents* LocationBarViewGtk::GetTabContents() const { | 435 TabContents* LocationBarViewGtk::GetTabContents() const { |
418 return browser_->GetSelectedTabContents(); | 436 return browser_->GetSelectedTabContents(); |
419 } | 437 } |
420 | 438 |
(...skipping 128 matching lines...) Loading... | |
549 NotificationService::current()->Notify( | 567 NotificationService::current()->Notify( |
550 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, | 568 NotificationType::ACCESSIBILITY_CONTROL_FOCUSED, |
551 Source<Profile>(profile_), | 569 Source<Profile>(profile_), |
552 Details<AccessibilityTextBoxInfo>(&info)); | 570 Details<AccessibilityTextBoxInfo>(&info)); |
553 | 571 |
554 // Update the keyword and search hint states. | 572 // Update the keyword and search hint states. |
555 OnChanged(); | 573 OnChanged(); |
556 } | 574 } |
557 | 575 |
558 SkBitmap LocationBarViewGtk::GetFavIcon() const { | 576 SkBitmap LocationBarViewGtk::GetFavIcon() const { |
559 NOTIMPLEMENTED(); | 577 return GetTabContents()->GetFavIcon(); |
560 return SkBitmap(); | |
561 } | 578 } |
562 | 579 |
563 std::wstring LocationBarViewGtk::GetTitle() const { | 580 std::wstring LocationBarViewGtk::GetTitle() const { |
564 NOTIMPLEMENTED(); | 581 return UTF16ToWideHack(GetTabContents()->GetTitle()); |
565 return std::wstring(); | |
566 } | 582 } |
567 | 583 |
568 void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { | 584 void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { |
569 // We need the browser window to be shown before we can show the bubble, but | 585 // We need the browser window to be shown before we can show the bubble, but |
570 // we get called before that's happened. | 586 // we get called before that's happened. |
571 Task* task = first_run_bubble_.NewRunnableMethod( | 587 Task* task = first_run_bubble_.NewRunnableMethod( |
572 &LocationBarViewGtk::ShowFirstRunBubbleInternal, bubble_type); | 588 &LocationBarViewGtk::ShowFirstRunBubbleInternal, bubble_type); |
573 MessageLoop::current()->PostTask(FROM_HERE, task); | 589 MessageLoop::current()->PostTask(FROM_HERE, task); |
574 } | 590 } |
575 | 591 |
(...skipping 385 matching lines...) Loading... | |
961 void LocationBarViewGtk::OnIconDragData(GtkWidget* sender, | 977 void LocationBarViewGtk::OnIconDragData(GtkWidget* sender, |
962 GdkDragContext* context, | 978 GdkDragContext* context, |
963 GtkSelectionData* data, | 979 GtkSelectionData* data, |
964 guint info, guint time) { | 980 guint info, guint time) { |
965 TabContents* tab = GetTabContents(); | 981 TabContents* tab = GetTabContents(); |
966 if (!tab) | 982 if (!tab) |
967 return; | 983 return; |
968 gtk_dnd_util::WriteURLWithName(data, tab->GetURL(), tab->GetTitle(), info); | 984 gtk_dnd_util::WriteURLWithName(data, tab->GetURL(), tab->GetTitle(), info); |
969 } | 985 } |
970 | 986 |
987 void LocationBarViewGtk::OnIconDragBegin(GtkWidget* sender, | |
988 GdkDragContext* context) { | |
989 if (gtk_util::IsScreenComposited()) | |
990 gtk_drag_set_icon_widget(context, drag_icon_.get(), 0, 0); | |
991 } | |
992 | |
993 gboolean LocationBarViewGtk::OnDragIconExpose(GtkWidget* sender, | |
994 GdkEventExpose* event) { | |
995 // Clear the background. | |
996 cairo_t* cr = gdk_cairo_create(event->window); | |
997 gdk_cairo_rectangle(cr, &event->area); | |
998 cairo_clip(cr); | |
999 cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); | |
1000 cairo_paint(cr); | |
1001 cairo_destroy(cr); | |
1002 | |
1003 // 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
| |
1004 gfx::CanvasPaint canvas(event, false); | |
1005 SkBitmap icon = GetFavIcon(); | |
1006 canvas.DrawBitmapInt(icon, 0, 0); | |
1007 | |
1008 // Paint the title text. | |
1009 int text_x = icon.width() + kFavIconTitleSpacing; | |
1010 int text_width = sender->allocation.width - text_x; | |
1011 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
1012 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | |
1013 canvas.DrawStringInt(GetTitle(), | |
1014 base_font, SK_ColorBLACK, | |
1015 text_x, 0, text_width, sender->allocation.height); | |
1016 | |
1017 return TRUE; | |
1018 } | |
1019 | |
971 void LocationBarViewGtk::OnEntryBoxSizeAllocate(GtkWidget* sender, | 1020 void LocationBarViewGtk::OnEntryBoxSizeAllocate(GtkWidget* sender, |
972 GtkAllocation* allocation) { | 1021 GtkAllocation* allocation) { |
973 if (entry_box_width_ != allocation->width) { | 1022 if (entry_box_width_ != allocation->width) { |
974 entry_box_width_ = allocation->width; | 1023 entry_box_width_ = allocation->width; |
975 AdjustChildrenVisibility(); | 1024 AdjustChildrenVisibility(); |
976 } | 1025 } |
977 } | 1026 } |
978 | 1027 |
979 gboolean LocationBarViewGtk::OnStarButtonPress(GtkWidget* widget, | 1028 gboolean LocationBarViewGtk::OnStarButtonPress(GtkWidget* widget, |
980 GdkEventButton* event) { | 1029 GdkEventButton* event) { |
(...skipping 381 matching lines...) Loading... | |
1362 | 1411 |
1363 std::string badge_text = page_action_->GetBadgeText(tab_id); | 1412 std::string badge_text = page_action_->GetBadgeText(tab_id); |
1364 if (badge_text.empty()) | 1413 if (badge_text.empty()) |
1365 return FALSE; | 1414 return FALSE; |
1366 | 1415 |
1367 gfx::CanvasPaint canvas(event, false); | 1416 gfx::CanvasPaint canvas(event, false); |
1368 gfx::Rect bounding_rect(widget->allocation); | 1417 gfx::Rect bounding_rect(widget->allocation); |
1369 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); | 1418 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); |
1370 return FALSE; | 1419 return FALSE; |
1371 } | 1420 } |
OLD | NEW |