| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/browser/search_engines/template_url_model.h" | 23 #include "chrome/browser/search_engines/template_url_model.h" |
| 24 #include "chrome/browser/tab_contents/tab_contents.h" | 24 #include "chrome/browser/tab_contents/tab_contents.h" |
| 25 #include "chrome/common/gtk_util.h" | 25 #include "chrome/common/gtk_util.h" |
| 26 #include "chrome/common/page_transition_types.h" | 26 #include "chrome/common/page_transition_types.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 #include "third_party/skia/include/core/SkBitmap.h" | 28 #include "third_party/skia/include/core/SkBitmap.h" |
| 29 #include "webkit/glue/window_open_disposition.h" | 29 #include "webkit/glue/window_open_disposition.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Top and bottom padding/margin | |
| 34 // We are positioned with a little bit of extra space that we don't use now. | 33 // We are positioned with a little bit of extra space that we don't use now. |
| 35 const int kTopMargin = 1; | 34 const int kTopMargin = 1; |
| 36 const int kBottomMargin = 1; | 35 const int kBottomMargin = 1; |
| 36 const int kLeftMargin = 1; |
| 37 const int kRightMargin = 1; |
| 37 // We draw a border on the top and bottom (but not on left or right). | 38 // We draw a border on the top and bottom (but not on left or right). |
| 38 const int kBorderThickness = 1; | 39 const int kBorderThickness = 1; |
| 39 | 40 |
| 40 // Left margin of first run bubble. | 41 // Left margin of first run bubble. |
| 41 const int kFirstRunBubbleLeftMargin = 8; | 42 const int kFirstRunBubbleLeftMargin = 8; |
| 42 // Extra vertical spacing for first run bubble. | 43 // Extra vertical spacing for first run bubble. |
| 43 const int kFirstRunBubbleTopMargin = 1; | 44 const int kFirstRunBubbleTopMargin = 1; |
| 44 // Task delay (in milliseconds) to show first run bubble. | 45 // Task delay (in milliseconds) to show first run bubble. |
| 45 const int kFirstRunBubbleTaskDelay = 200; | 46 const int kFirstRunBubbleTaskDelay = 200; |
| 46 | 47 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 tab_to_search_hint_(NULL), | 106 tab_to_search_hint_(NULL), |
| 106 tab_to_search_hint_leading_label_(NULL), | 107 tab_to_search_hint_leading_label_(NULL), |
| 107 tab_to_search_hint_icon_(NULL), | 108 tab_to_search_hint_icon_(NULL), |
| 108 tab_to_search_hint_trailing_label_(NULL), | 109 tab_to_search_hint_trailing_label_(NULL), |
| 109 profile_(NULL), | 110 profile_(NULL), |
| 110 command_updater_(command_updater), | 111 command_updater_(command_updater), |
| 111 toolbar_model_(toolbar_model), | 112 toolbar_model_(toolbar_model), |
| 112 popup_positioner_(popup_positioner), | 113 popup_positioner_(popup_positioner), |
| 113 disposition_(CURRENT_TAB), | 114 disposition_(CURRENT_TAB), |
| 114 transition_(PageTransition::TYPED), | 115 transition_(PageTransition::TYPED), |
| 115 first_run_bubble_(this) { | 116 first_run_bubble_(this), |
| 117 popup_window_mode_(false) { |
| 116 } | 118 } |
| 117 | 119 |
| 118 LocationBarViewGtk::~LocationBarViewGtk() { | 120 LocationBarViewGtk::~LocationBarViewGtk() { |
| 119 // All of our widgets should have be children of / owned by the alignment. | 121 // All of our widgets should have be children of / owned by the alignment. |
| 120 hbox_.Destroy(); | 122 hbox_.Destroy(); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void LocationBarViewGtk::Init() { | 125 void LocationBarViewGtk::Init(bool popup_window_mode) { |
| 126 popup_window_mode_ = popup_window_mode; |
| 124 location_entry_.reset(new AutocompleteEditViewGtk(this, | 127 location_entry_.reset(new AutocompleteEditViewGtk(this, |
| 125 toolbar_model_, | 128 toolbar_model_, |
| 126 profile_, | 129 profile_, |
| 127 command_updater_, | 130 command_updater_, |
| 131 popup_window_mode_, |
| 128 popup_positioner_)); | 132 popup_positioner_)); |
| 129 location_entry_->Init(); | 133 location_entry_->Init(); |
| 130 | 134 |
| 131 hbox_.Own(gtk_hbox_new(FALSE, 0)); | 135 hbox_.Own(gtk_hbox_new(FALSE, 0)); |
| 132 // We will paint for the alignment, to paint the background and border. | 136 // We will paint for the alignment, to paint the background and border. |
| 133 gtk_widget_set_app_paintable(hbox_.get(), TRUE); | 137 gtk_widget_set_app_paintable(hbox_.get(), TRUE); |
| 134 // Have GTK double buffer around the expose signal. | 138 // Have GTK double buffer around the expose signal. |
| 135 gtk_widget_set_double_buffered(hbox_.get(), TRUE); | 139 gtk_widget_set_double_buffered(hbox_.get(), TRUE); |
| 136 // Redraw the whole location bar when it changes size (e.g., when toggling | 140 // Redraw the whole location bar when it changes size (e.g., when toggling |
| 137 // the home button on/off. | 141 // the home button on/off. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 tab_to_search_label_, &kKeywordBackgroundColor, 1, 1, 2, 2), | 173 tab_to_search_label_, &kKeywordBackgroundColor, 1, 1, 2, 2), |
| 170 &kKeywordBorderColor, 1, 1, 1, 1)); | 174 &kKeywordBorderColor, 1, 1, 1, 1)); |
| 171 | 175 |
| 172 gtk_box_pack_start(GTK_BOX(hbox_.get()), tab_to_search_, FALSE, FALSE, 0); | 176 gtk_box_pack_start(GTK_BOX(hbox_.get()), tab_to_search_, FALSE, FALSE, 0); |
| 173 | 177 |
| 174 GtkWidget* align = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | 178 GtkWidget* align = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 175 // TODO(erg): Like in BrowserToolbarGtk, this used to have a code path on | 179 // TODO(erg): Like in BrowserToolbarGtk, this used to have a code path on |
| 176 // construction for with GTK themes and without. Doing that only on | 180 // construction for with GTK themes and without. Doing that only on |
| 177 // construction was wrong, and I can't see a difference between the two ways | 181 // construction was wrong, and I can't see a difference between the two ways |
| 178 // anyway... Investigate more later. | 182 // anyway... Investigate more later. |
| 179 gtk_alignment_set_padding(GTK_ALIGNMENT(align), | 183 if (popup_window_mode_) { |
| 180 kTopMargin + kBorderThickness, | 184 gtk_alignment_set_padding(GTK_ALIGNMENT(align), |
| 181 kBottomMargin + kBorderThickness, | 185 kTopMargin + kBorderThickness, |
| 182 kEditLeftRightPadding, kEditLeftRightPadding); | 186 kBottomMargin + kBorderThickness, |
| 187 kEditLeftRightPadding + kBorderThickness, |
| 188 kEditLeftRightPadding + kBorderThickness); |
| 189 } else { |
| 190 gtk_alignment_set_padding(GTK_ALIGNMENT(align), |
| 191 kTopMargin + kBorderThickness, |
| 192 kBottomMargin + kBorderThickness, |
| 193 kEditLeftRightPadding, kEditLeftRightPadding); |
| 194 } |
| 183 gtk_container_add(GTK_CONTAINER(align), location_entry_->widget()); | 195 gtk_container_add(GTK_CONTAINER(align), location_entry_->widget()); |
| 184 gtk_box_pack_start(GTK_BOX(hbox_.get()), align, TRUE, TRUE, 0); | 196 gtk_box_pack_start(GTK_BOX(hbox_.get()), align, TRUE, TRUE, 0); |
| 185 | 197 |
| 186 // Tab to search notification (the hint on the right hand side). | 198 // Tab to search notification (the hint on the right hand side). |
| 187 tab_to_search_hint_ = gtk_hbox_new(FALSE, 0); | 199 tab_to_search_hint_ = gtk_hbox_new(FALSE, 0); |
| 188 tab_to_search_hint_leading_label_ = gtk_label_new(NULL); | 200 tab_to_search_hint_leading_label_ = gtk_label_new(NULL); |
| 189 tab_to_search_hint_icon_ = gtk_image_new_from_pixbuf( | 201 tab_to_search_hint_icon_ = gtk_image_new_from_pixbuf( |
| 190 rb.GetPixbufNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB)); | 202 rb.GetPixbufNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB)); |
| 191 tab_to_search_hint_trailing_label_ = gtk_label_new(NULL); | 203 tab_to_search_hint_trailing_label_ = gtk_label_new(NULL); |
| 192 gtk_box_pack_start(GTK_BOX(tab_to_search_hint_), | 204 gtk_box_pack_start(GTK_BOX(tab_to_search_hint_), |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 GdkRectangle inner_rect = { | 394 GdkRectangle inner_rect = { |
| 383 alloc_rect->x, | 395 alloc_rect->x, |
| 384 alloc_rect->y + kTopMargin, | 396 alloc_rect->y + kTopMargin, |
| 385 alloc_rect->width, | 397 alloc_rect->width, |
| 386 alloc_rect->height - kTopMargin - kBottomMargin}; | 398 alloc_rect->height - kTopMargin - kBottomMargin}; |
| 387 | 399 |
| 388 // Some of our calculations are a bit sloppy. Since we draw on our parent | 400 // Some of our calculations are a bit sloppy. Since we draw on our parent |
| 389 // window, set a clip to make sure that we don't draw outside. | 401 // window, set a clip to make sure that we don't draw outside. |
| 390 gdk_gc_set_clip_rectangle(gc, &inner_rect); | 402 gdk_gc_set_clip_rectangle(gc, &inner_rect); |
| 391 | 403 |
| 392 // If we're not using GTK theming, draw our own border. | 404 // Draw the background. |
| 405 gdk_gc_set_rgb_fg_color(gc, |
| 406 &kBackgroundColorByLevel[toolbar_model_->GetSchemeSecurityLevel()]); |
| 407 gdk_draw_rectangle(drawable, gc, TRUE, |
| 408 inner_rect.x, |
| 409 inner_rect.y, |
| 410 inner_rect.width, |
| 411 inner_rect.height); |
| 412 |
| 413 // If we're not using GTK theming, draw our own border over the edge pixels |
| 414 // of the background. |
| 393 if (!profile_ || | 415 if (!profile_ || |
| 394 !GtkThemeProvider::GetFrom(profile_)->UseGtkTheme()) { | 416 !GtkThemeProvider::GetFrom(profile_)->UseGtkTheme()) { |
| 395 // Draw our 1px border. TODO(deanm): Maybe this would be cleaner as an | 417 // Draw our 1px border. TODO(deanm): Maybe this would be cleaner as an |
| 396 // overdrawn stroked rect with a clip to the allocation? | 418 // overdrawn stroked rect with a clip to the allocation? |
| 397 gdk_gc_set_rgb_fg_color(gc, &kBorderColor); | 419 gdk_gc_set_rgb_fg_color(gc, &kBorderColor); |
| 398 gdk_draw_rectangle(drawable, gc, TRUE, | 420 gdk_draw_rectangle(drawable, gc, TRUE, |
| 399 inner_rect.x, | 421 inner_rect.x, |
| 400 inner_rect.y, | 422 inner_rect.y, |
| 401 inner_rect.width, | 423 inner_rect.width, |
| 402 kBorderThickness); | 424 kBorderThickness); |
| 403 gdk_draw_rectangle(drawable, gc, TRUE, | 425 gdk_draw_rectangle(drawable, gc, TRUE, |
| 404 inner_rect.x, | 426 inner_rect.x, |
| 405 inner_rect.y + inner_rect.height - kBorderThickness, | 427 inner_rect.y + inner_rect.height - kBorderThickness, |
| 406 inner_rect.width, | 428 inner_rect.width, |
| 407 kBorderThickness); | 429 kBorderThickness); |
| 430 if (popup_window_mode_) { |
| 431 gdk_draw_rectangle(drawable, gc, TRUE, |
| 432 inner_rect.x, |
| 433 inner_rect.y, |
| 434 kBorderThickness, |
| 435 inner_rect.height); |
| 436 gdk_draw_rectangle(drawable, gc, TRUE, |
| 437 inner_rect.x + inner_rect.width - kBorderThickness, |
| 438 inner_rect.y, |
| 439 kBorderThickness, |
| 440 inner_rect.height); |
| 441 } |
| 408 } | 442 } |
| 409 | 443 |
| 410 // Draw the background within the border. | |
| 411 gdk_gc_set_rgb_fg_color(gc, | |
| 412 &kBackgroundColorByLevel[toolbar_model_->GetSchemeSecurityLevel()]); | |
| 413 gdk_draw_rectangle(drawable, gc, TRUE, | |
| 414 inner_rect.x, | |
| 415 inner_rect.y + kBorderThickness, | |
| 416 inner_rect.width, | |
| 417 inner_rect.height - (kBorderThickness * 2)); | |
| 418 | |
| 419 g_object_unref(gc); | 444 g_object_unref(gc); |
| 420 | 445 |
| 421 return FALSE; // Continue propagating the expose. | 446 return FALSE; // Continue propagating the expose. |
| 422 } | 447 } |
| 423 | 448 |
| 424 void LocationBarViewGtk::SetSecurityIcon(ToolbarModel::Icon icon) { | 449 void LocationBarViewGtk::SetSecurityIcon(ToolbarModel::Icon icon) { |
| 425 gtk_widget_hide(GTK_WIDGET(security_lock_icon_image_)); | 450 gtk_widget_hide(GTK_WIDGET(security_lock_icon_image_)); |
| 426 gtk_widget_hide(GTK_WIDGET(security_warning_icon_image_)); | 451 gtk_widget_hide(GTK_WIDGET(security_warning_icon_image_)); |
| 427 if (icon != ToolbarModel::NO_ICON) | 452 if (icon != ToolbarModel::NO_ICON) |
| 428 gtk_widget_show(GTK_WIDGET(security_icon_align_)); | 453 gtk_widget_show(GTK_WIDGET(security_icon_align_)); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // The bubble needs to be just below the Omnibox and slightly to the right | 542 // The bubble needs to be just below the Omnibox and slightly to the right |
| 518 // of star button, so shift x and y co-ordinates. | 543 // of star button, so shift x and y co-ordinates. |
| 519 x += widget()->allocation.x + kFirstRunBubbleLeftMargin; | 544 x += widget()->allocation.x + kFirstRunBubbleLeftMargin; |
| 520 y += widget()->allocation.y + widget()->allocation.height + | 545 y += widget()->allocation.y + widget()->allocation.height + |
| 521 kFirstRunBubbleTopMargin; | 546 kFirstRunBubbleTopMargin; |
| 522 | 547 |
| 523 FirstRunBubble::Show(profile_, | 548 FirstRunBubble::Show(profile_, |
| 524 GTK_WINDOW(gtk_widget_get_toplevel(widget())), | 549 GTK_WINDOW(gtk_widget_get_toplevel(widget())), |
| 525 gfx::Rect(x, y, 0, 0), use_OEM_bubble); | 550 gfx::Rect(x, y, 0, 0), use_OEM_bubble); |
| 526 } | 551 } |
| OLD | NEW |