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

Side by Side Diff: chrome/browser/gtk/location_bar_view_gtk.cc

Issue 348029: GTK: Use background images for location bar, instead of faking it. (Closed)
Patch Set: Created 11 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gfx/canvas_paint.h" 9 #include "app/gfx/canvas_paint.h"
10 #include "app/gfx/gtk_util.h" 10 #include "app/gfx/gtk_util.h"
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "chrome/app/chrome_dll_resource.h" 16 #include "chrome/app/chrome_dll_resource.h"
17 #include "chrome/browser/alternate_nav_url_fetcher.h" 17 #include "chrome/browser/alternate_nav_url_fetcher.h"
18 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" 18 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
19 #include "chrome/browser/browser.h" 19 #include "chrome/browser/browser.h"
20 #include "chrome/browser/browser_list.h" 20 #include "chrome/browser/browser_list.h"
21 #include "chrome/browser/command_updater.h" 21 #include "chrome/browser/command_updater.h"
22 #include "chrome/browser/extensions/extension_browser_event_router.h" 22 #include "chrome/browser/extensions/extension_browser_event_router.h"
23 #include "chrome/browser/extensions/extension_tabs_module.h" 23 #include "chrome/browser/extensions/extension_tabs_module.h"
24 #include "chrome/browser/gtk/cairo_cached_surface.h"
24 #include "chrome/browser/gtk/first_run_bubble.h" 25 #include "chrome/browser/gtk/first_run_bubble.h"
25 #include "chrome/browser/gtk/gtk_theme_provider.h" 26 #include "chrome/browser/gtk/gtk_theme_provider.h"
26 #include "chrome/browser/gtk/rounded_window.h" 27 #include "chrome/browser/gtk/rounded_window.h"
27 #include "chrome/browser/profile.h" 28 #include "chrome/browser/profile.h"
28 #include "chrome/browser/search_engines/template_url.h" 29 #include "chrome/browser/search_engines/template_url.h"
29 #include "chrome/browser/search_engines/template_url_model.h" 30 #include "chrome/browser/search_engines/template_url_model.h"
30 #include "chrome/browser/tab_contents/tab_contents.h" 31 #include "chrome/browser/tab_contents/tab_contents.h"
31 #include "chrome/common/gtk_util.h" 32 #include "chrome/common/gtk_util.h"
32 #include "chrome/common/notification_service.h" 33 #include "chrome/common/notification_service.h"
33 #include "chrome/common/page_transition_types.h" 34 #include "chrome/common/page_transition_types.h"
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 gtk_util::SetLabelColor(tab_to_search_label_, &gfx::kGdkBlack); 489 gtk_util::SetLabelColor(tab_to_search_label_, &gfx::kGdkBlack);
489 gtk_util::SetLabelColor(tab_to_search_hint_leading_label_, 490 gtk_util::SetLabelColor(tab_to_search_hint_leading_label_,
490 &gfx::kGdkBlack); 491 &gfx::kGdkBlack);
491 gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_, 492 gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_,
492 &gfx::kGdkBlack); 493 &gfx::kGdkBlack);
493 } 494 }
494 } 495 }
495 496
496 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget, 497 gboolean LocationBarViewGtk::HandleExpose(GtkWidget* widget,
497 GdkEventExpose* event) { 498 GdkEventExpose* event) {
498 GdkDrawable* drawable = GDK_DRAWABLE(event->window);
499 GdkRectangle* alloc_rect = &hbox_->allocation; 499 GdkRectangle* alloc_rect = &hbox_->allocation;
500 500
501 // The area outside of our margin, which includes the border.
502 GdkRectangle inner_rect = {
503 alloc_rect->x,
504 alloc_rect->y + kTopMargin,
505 alloc_rect->width,
506 alloc_rect->height - kTopMargin - kBottomMargin};
507
508 // If we're not using GTK theming, draw our own border over the edge pixels 501 // If we're not using GTK theming, draw our own border over the edge pixels
509 // of the background. 502 // of the background.
510 if (!profile_ || 503 if (!profile_ ||
511 !GtkThemeProvider::GetFrom(profile_)->UseGtkTheme()) { 504 !GtkThemeProvider::GetFrom(profile_)->UseGtkTheme()) {
512 GdkGC* gc = gdk_gc_new(drawable); 505 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(event->window));
506 cairo_rectangle(cr, event->area.x, event->area.y, event->area.width,
Evan Stade 2009/10/30 23:24:52 can use gdk_cairo_rectangle(cr, &event->area)
507 event->area.height);
508 cairo_clip(cr);
509 CairoCachedSurface* background = theme_provider_->GetSurfaceNamed(
510 popup_window_mode_ ? IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG,
511 widget);
513 512
514 // Some of our calculations are a bit sloppy. Since we draw on our parent 513 // We paint the source to the "outer" rect, which is the size of the hbox's
515 // window, set a clip to make sure that we don't draw outside. 514 // allocation. This image blends with whatever is behind it as the top and
516 gdk_gc_set_clip_rectangle(gc, &inner_rect); 515 // bottom fade out.
516 background->SetSource(cr, alloc_rect->x, alloc_rect->y);
517 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
518 cairo_rectangle(cr, alloc_rect->x, alloc_rect->y,
519 alloc_rect->width, alloc_rect->height);
520 cairo_fill(cr);
517 521
518 // Draw the background. 522 // But on top of that, we also need to draw the "inner" rect, which is all
519 gdk_gc_set_rgb_fg_color(gc, 523 // the color that the background should be.
520 &kBackgroundColorByLevel[toolbar_model_->GetSchemeSecurityLevel()]); 524 cairo_rectangle(cr, alloc_rect->x,
521 gdk_draw_rectangle(drawable, gc, TRUE, 525 alloc_rect->y + kTopMargin + kBorderThickness,
522 inner_rect.x, 526 alloc_rect->width,
523 inner_rect.y, 527 alloc_rect->height - kTopMargin -
524 inner_rect.width, 528 kBottomMargin - 2 * kBorderThickness);
525 inner_rect.height); 529 gdk_cairo_set_source_color(cr, const_cast<GdkColor*>(
530 &kBackgroundColorByLevel[toolbar_model_->GetSchemeSecurityLevel()]));
531 cairo_fill(cr);
526 532
527 // Draw our 1px border. TODO(deanm): Maybe this would be cleaner as an 533 cairo_destroy(cr);
528 // overdrawn stroked rect with a clip to the allocation?
529 gdk_gc_set_rgb_fg_color(gc, &kBorderColor);
530 gdk_draw_rectangle(drawable, gc, TRUE,
531 inner_rect.x,
532 inner_rect.y,
533 inner_rect.width,
534 kBorderThickness);
535 gdk_draw_rectangle(drawable, gc, TRUE,
536 inner_rect.x,
537 inner_rect.y + inner_rect.height - kBorderThickness,
538 inner_rect.width,
539 kBorderThickness);
540 if (popup_window_mode_) {
541 gdk_draw_rectangle(drawable, gc, TRUE,
542 inner_rect.x,
543 inner_rect.y,
544 kBorderThickness,
545 inner_rect.height);
546 gdk_draw_rectangle(drawable, gc, TRUE,
547 inner_rect.x + inner_rect.width - kBorderThickness,
548 inner_rect.y,
549 kBorderThickness,
550 inner_rect.height);
551 }
552
553 g_object_unref(gc);
554 } 534 }
555 535
556 return FALSE; // Continue propagating the expose. 536 return FALSE; // Continue propagating the expose.
557 } 537 }
558 538
559 void LocationBarViewGtk::SetSecurityIcon(ToolbarModel::Icon icon) { 539 void LocationBarViewGtk::SetSecurityIcon(ToolbarModel::Icon icon) {
560 gtk_widget_hide(GTK_WIDGET(security_lock_icon_image_)); 540 gtk_widget_hide(GTK_WIDGET(security_lock_icon_image_));
561 gtk_widget_hide(GTK_WIDGET(security_warning_icon_image_)); 541 gtk_widget_hide(GTK_WIDGET(security_warning_icon_image_));
562 if (icon != ToolbarModel::NO_ICON) 542 if (icon != ToolbarModel::NO_ICON)
563 gtk_widget_show(GTK_WIDGET(security_icon_event_box_)); 543 gtk_widget_show(GTK_WIDGET(security_icon_event_box_));
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 837
858 std::string badge_text = view->page_action_->GetBadgeText(tab_id); 838 std::string badge_text = view->page_action_->GetBadgeText(tab_id);
859 if (badge_text.empty()) 839 if (badge_text.empty())
860 return FALSE; 840 return FALSE;
861 841
862 gfx::CanvasPaint canvas(event, false); 842 gfx::CanvasPaint canvas(event, false);
863 gfx::Rect bounding_rect(widget->allocation); 843 gfx::Rect bounding_rect(widget->allocation);
864 view->page_action_->PaintBadge(&canvas, bounding_rect, tab_id); 844 view->page_action_->PaintBadge(&canvas, bounding_rect, tab_id);
865 return FALSE; 845 return FALSE;
866 } 846 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698