OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/find_bar_gtk.h" | 5 #include "chrome/browser/ui/gtk/find_bar_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 ignore_changed_signal_ = true; | 365 ignore_changed_signal_ = true; |
366 gtk_entry_set_text(GTK_ENTRY(text_entry_), find_text_utf8.c_str()); | 366 gtk_entry_set_text(GTK_ENTRY(text_entry_), find_text_utf8.c_str()); |
367 ignore_changed_signal_ = false; | 367 ignore_changed_signal_ = false; |
368 } | 368 } |
369 | 369 |
370 void FindBarGtk::UpdateUIForFindResult(const FindNotificationDetails& result, | 370 void FindBarGtk::UpdateUIForFindResult(const FindNotificationDetails& result, |
371 const string16& find_text) { | 371 const string16& find_text) { |
372 if (!result.selection_rect().IsEmpty()) { | 372 if (!result.selection_rect().IsEmpty()) { |
373 selection_rect_ = result.selection_rect(); | 373 selection_rect_ = result.selection_rect(); |
374 int xposition = GetDialogPosition(result.selection_rect()).x(); | 374 int xposition = GetDialogPosition(result.selection_rect()).x(); |
375 if (xposition != widget()->allocation.x) | 375 GtkAllocation allocation; |
| 376 gtk_widget_get_allocation(widget(), &allocation); |
| 377 if (xposition != allocation.x) |
376 Reposition(); | 378 Reposition(); |
377 } | 379 } |
378 | 380 |
379 // Once we find a match we no longer want to keep track of what had | 381 // Once we find a match we no longer want to keep track of what had |
380 // focus. EndFindSession will then set the focus to the page content. | 382 // focus. EndFindSession will then set the focus to the page content. |
381 if (result.number_of_matches() > 0) | 383 if (result.number_of_matches() > 0) |
382 focus_store_.Store(NULL); | 384 focus_store_.Store(NULL); |
383 | 385 |
384 std::string find_text_utf8 = UTF16ToUTF8(find_text); | 386 std::string find_text_utf8 = UTF16ToUTF8(find_text); |
385 bool have_valid_range = | 387 bool have_valid_range = |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 // static | 809 // static |
808 gboolean FindBarGtk::OnContentEventBoxExpose(GtkWidget* widget, | 810 gboolean FindBarGtk::OnContentEventBoxExpose(GtkWidget* widget, |
809 GdkEventExpose* event, | 811 GdkEventExpose* event, |
810 FindBarGtk* bar) { | 812 FindBarGtk* bar) { |
811 if (bar->theme_service_->UsingNativeTheme()) { | 813 if (bar->theme_service_->UsingNativeTheme()) { |
812 // Draw the text entry background around where we input stuff. Note the | 814 // Draw the text entry background around where we input stuff. Note the |
813 // decrement to |width|. We do this because some theme engines | 815 // decrement to |width|. We do this because some theme engines |
814 // (*cough*Clearlooks*cough*) don't do any blending and use thickness to | 816 // (*cough*Clearlooks*cough*) don't do any blending and use thickness to |
815 // make sure that widgets never overlap. | 817 // make sure that widgets never overlap. |
816 int padding = gtk_widget_get_style(widget)->xthickness; | 818 int padding = gtk_widget_get_style(widget)->xthickness; |
817 GdkRectangle rec = { | 819 GdkRectangle rec; |
818 widget->allocation.x, | 820 gtk_widget_get_allocation(widget, &rec); |
819 widget->allocation.y, | 821 rec.width -= padding; |
820 widget->allocation.width - padding, | |
821 widget->allocation.height | |
822 }; | |
823 | 822 |
824 gtk_util::DrawTextEntryBackground(bar->text_entry_, widget, | 823 gtk_util::DrawTextEntryBackground(bar->text_entry_, widget, |
825 &event->area, &rec); | 824 &event->area, &rec); |
826 } | 825 } |
827 | 826 |
828 return FALSE; | 827 return FALSE; |
829 } | 828 } |
830 | 829 |
831 // Used to handle custom painting of |container_|. | 830 // Used to handle custom painting of |container_|. |
832 gboolean FindBarGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e, | 831 gboolean FindBarGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e, |
833 FindBarGtk* bar) { | 832 FindBarGtk* bar) { |
| 833 GtkAllocation allocation; |
| 834 gtk_widget_get_allocation(widget, &allocation); |
| 835 |
834 if (bar->theme_service_->UsingNativeTheme()) { | 836 if (bar->theme_service_->UsingNativeTheme()) { |
835 if (bar->container_width_ != widget->allocation.width || | 837 if (bar->container_width_ != allocation.width || |
836 bar->container_height_ != widget->allocation.height) { | 838 bar->container_height_ != allocation.height) { |
837 std::vector<GdkPoint> mask_points = MakeFramePolygonPoints( | 839 std::vector<GdkPoint> mask_points = MakeFramePolygonPoints( |
838 widget->allocation.width, widget->allocation.height, FRAME_MASK); | 840 allocation.width, allocation.height, FRAME_MASK); |
839 GdkRegion* mask_region = gdk_region_polygon(&mask_points[0], | 841 GdkRegion* mask_region = gdk_region_polygon(&mask_points[0], |
840 mask_points.size(), | 842 mask_points.size(), |
841 GDK_EVEN_ODD_RULE); | 843 GDK_EVEN_ODD_RULE); |
842 // Reset the shape. | 844 // Reset the shape. |
843 gdk_window_shape_combine_region(widget->window, NULL, 0, 0); | 845 gdk_window_shape_combine_region(widget->window, NULL, 0, 0); |
844 gdk_window_shape_combine_region(widget->window, mask_region, 0, 0); | 846 gdk_window_shape_combine_region(widget->window, mask_region, 0, 0); |
845 gdk_region_destroy(mask_region); | 847 gdk_region_destroy(mask_region); |
846 | 848 |
847 bar->container_width_ = widget->allocation.width; | 849 bar->container_width_ = allocation.width; |
848 bar->container_height_ = widget->allocation.height; | 850 bar->container_height_ = allocation.height; |
849 } | 851 } |
850 | 852 |
851 GdkDrawable* drawable = GDK_DRAWABLE(e->window); | 853 GdkDrawable* drawable = GDK_DRAWABLE(e->window); |
852 GdkGC* gc = gdk_gc_new(drawable); | 854 GdkGC* gc = gdk_gc_new(drawable); |
853 gdk_gc_set_clip_rectangle(gc, &e->area); | 855 gdk_gc_set_clip_rectangle(gc, &e->area); |
854 GdkColor color = bar->theme_service_->GetBorderColor(); | 856 GdkColor color = bar->theme_service_->GetBorderColor(); |
855 gdk_gc_set_rgb_fg_color(gc, &color); | 857 gdk_gc_set_rgb_fg_color(gc, &color); |
856 | 858 |
857 // Stroke the frame border. | 859 // Stroke the frame border. |
858 std::vector<GdkPoint> points = MakeFramePolygonPoints( | 860 std::vector<GdkPoint> points = MakeFramePolygonPoints( |
859 widget->allocation.width, widget->allocation.height, FRAME_STROKE); | 861 allocation.width, allocation.height, FRAME_STROKE); |
860 gdk_draw_lines(drawable, gc, &points[0], points.size()); | 862 gdk_draw_lines(drawable, gc, &points[0], points.size()); |
861 | 863 |
862 g_object_unref(gc); | 864 g_object_unref(gc); |
863 } else { | 865 } else { |
864 if (bar->container_width_ != widget->allocation.width || | 866 if (bar->container_width_ != allocation.width || |
865 bar->container_height_ != widget->allocation.height) { | 867 bar->container_height_ != allocation.height) { |
866 // Reset the shape. | 868 // Reset the shape. |
867 gdk_window_shape_combine_region(widget->window, NULL, 0, 0); | 869 gdk_window_shape_combine_region(widget->window, NULL, 0, 0); |
868 SetDialogShape(bar->container_); | 870 SetDialogShape(bar->container_); |
869 | 871 |
870 bar->container_width_ = widget->allocation.width; | 872 bar->container_width_ = allocation.width; |
871 bar->container_height_ = widget->allocation.height; | 873 bar->container_height_ = allocation.height; |
872 } | 874 } |
873 | 875 |
874 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 876 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
875 gdk_cairo_rectangle(cr, &e->area); | 877 gdk_cairo_rectangle(cr, &e->area); |
876 cairo_clip(cr); | 878 cairo_clip(cr); |
877 | 879 |
878 gfx::Point tabstrip_origin = | 880 gfx::Point tabstrip_origin = |
879 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); | 881 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); |
880 | 882 |
881 gtk_util::DrawThemedToolbarBackground(widget, cr, e, tabstrip_origin, | 883 gtk_util::DrawThemedToolbarBackground(widget, cr, e, tabstrip_origin, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 return FALSE; // Continue propagation. | 974 return FALSE; // Continue propagation. |
973 } | 975 } |
974 | 976 |
975 gboolean FindBarGtk::OnFocusOut(GtkWidget* entry, GdkEventFocus* event) { | 977 gboolean FindBarGtk::OnFocusOut(GtkWidget* entry, GdkEventFocus* event) { |
976 g_signal_handlers_disconnect_by_func( | 978 g_signal_handlers_disconnect_by_func( |
977 gdk_keymap_get_for_display(gtk_widget_get_display(entry)), | 979 gdk_keymap_get_for_display(gtk_widget_get_display(entry)), |
978 reinterpret_cast<gpointer>(&OnKeymapDirectionChanged), this); | 980 reinterpret_cast<gpointer>(&OnKeymapDirectionChanged), this); |
979 | 981 |
980 return FALSE; // Continue propagation. | 982 return FALSE; // Continue propagation. |
981 } | 983 } |
OLD | NEW |