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

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

Issue 100224: GTK: give the findbox curvy edges.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/find_bar_gtk.h ('k') | chrome/browser/gtk/nine_box.h » ('j') | 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/find_bar_gtk.h" 5 #include "chrome/browser/gtk/find_bar_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 8
9 #include "base/gfx/gtk_util.h" 9 #include "base/gfx/gtk_util.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "chrome/browser/find_bar_controller.h" 11 #include "chrome/browser/find_bar_controller.h"
12 #include "chrome/browser/gtk/browser_window_gtk.h" 12 #include "chrome/browser/gtk/browser_window_gtk.h"
13 #include "chrome/browser/gtk/custom_button.h" 13 #include "chrome/browser/gtk/custom_button.h"
14 #include "chrome/browser/gtk/nine_box.h"
14 #include "chrome/browser/gtk/tab_contents_container_gtk.h" 15 #include "chrome/browser/gtk/tab_contents_container_gtk.h"
15 #include "chrome/browser/tab_contents/web_contents.h" 16 #include "chrome/browser/tab_contents/web_contents.h"
16 #include "chrome/common/gtk_util.h" 17 #include "chrome/common/gtk_util.h"
17 #include "chrome/common/l10n_util.h" 18 #include "chrome/common/l10n_util.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 20
20 namespace { 21 namespace {
21 22
22 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4); 23 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4);
23 const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4); 24 const GdkColor kBorderColor = GDK_COLOR_RGB(0xbe, 0xc8, 0xd4);
(...skipping 11 matching lines...) Expand all
35 36
36 gboolean KeyPressEvent(GtkWindow* window, GdkEventKey* event, 37 gboolean KeyPressEvent(GtkWindow* window, GdkEventKey* event,
37 FindBarGtk* find_bar) { 38 FindBarGtk* find_bar) {
38 if (GDK_Escape == event->keyval) { 39 if (GDK_Escape == event->keyval) {
39 find_bar->EscapePressed(); 40 find_bar->EscapePressed();
40 return TRUE; 41 return TRUE;
41 } 42 }
42 return FALSE; 43 return FALSE;
43 } 44 }
44 45
46 // Get the ninebox that draws the background of |container_|. It is also used
47 // to change the shape of |container_|. The pointer is shared by all instances
48 // of FindBarGtk.
49 const NineBox* GetDialogBackground() {
50 static NineBox* dialog_backgroun = NULL;
51 if (!dialog_background) {
52 dialog_background = new NineBox(
53 IDR_FIND_DLG_LEFT_BACKGROUND,
54 IDR_FIND_DLG_MIDDLE_BACKGROUND,
55 IDR_FIND_DLG_RIGHT_BACKGROUND,
56 NULL, NULL, NULL, NULL, NULL, NULL);
57 dialog_background->ChangeWhiteToTransparent();
58 }
59
60 return dialog_background;
45 } 61 }
46 62
47 FindBarGtk::FindBarGtk(BrowserWindowGtk* browser) { 63 // Used to handle custom painting of |container_|.
64 gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e, gpointer userdata) {
65 GetDialogBackground()->RenderToWidget(widget);
66 GtkWidget* child = gtk_bin_get_child(GTK_BIN(widget));
67 if (child)
68 gtk_container_propagate_expose(GTK_CONTAINER(widget), child, e);
69 return TRUE;
70 }
71
72 } // namespace
73
74 FindBarGtk::FindBarGtk(BrowserWindowGtk* browser)
75 : container_shaped_(false) {
48 InitWidgets(); 76 InitWidgets();
49 77
50 // Insert the widget into the browser gtk hierarchy. 78 // Insert the widget into the browser gtk hierarchy.
51 browser->AddFindBar(this); 79 browser->AddFindBar(this);
52 80
53 // Hook up signals after the widget has been added to the hierarchy so the 81 // Hook up signals after the widget has been added to the hierarchy so the
54 // widget will be realized. 82 // widget will be realized.
55 g_signal_connect(find_text_, "changed", 83 g_signal_connect(find_text_, "changed",
56 G_CALLBACK(EntryContentsChanged), this); 84 G_CALLBACK(EntryContentsChanged), this);
57 g_signal_connect(find_text_, "key-press-event", 85 g_signal_connect(find_text_, "key-press-event",
58 G_CALLBACK(KeyPressEvent), this); 86 G_CALLBACK(KeyPressEvent), this);
59 g_signal_connect(widget(), "size-allocate", 87 g_signal_connect(widget(), "size-allocate",
60 G_CALLBACK(OnSizeAllocate), this); 88 G_CALLBACK(OnFixedSizeAllocate), this);
89 // We can't call ContourWidget() until after |container| has been
90 // allocated, hence we connect to this signal.
91 g_signal_connect(container_, "size-allocate",
92 G_CALLBACK(OnContainerSizeAllocate), this);
61 } 93 }
62 94
63 FindBarGtk::~FindBarGtk() { 95 FindBarGtk::~FindBarGtk() {
64 fixed_.Destroy(); 96 fixed_.Destroy();
65 } 97 }
66 98
67 void FindBarGtk::InitWidgets() { 99 void FindBarGtk::InitWidgets() {
68 // The find bar is basically an hbox with a gtkentry (text box) followed by 3 100 // The find bar is basically an hbox with a gtkentry (text box) followed by 3
69 // buttons (previous result, next result, close). We wrap the hbox in a gtk 101 // buttons (previous result, next result, close). We wrap the hbox in a gtk
70 // alignment and a gtk event box to get the padding and light blue 102 // alignment and a gtk event box to get the padding and light blue
71 // background. We put that event box in a fixed in order to control its 103 // background. We put that event box in a fixed in order to control its
72 // position. 104 // position.
73 GtkWidget* hbox = gtk_hbox_new(false, 0); 105 GtkWidget* hbox = gtk_hbox_new(false, 0);
74 container_ = gfx::CreateGtkBorderBin(hbox, &kBackgroundColor, 106 container_ = gfx::CreateGtkBorderBin(hbox, &kBackgroundColor,
75 kBarPadding, kBarPadding, kBarPadding, kBarPadding); 107 kBarPadding, kBarPadding, kBarPadding, kBarPadding);
76 fixed_.Own(gtk_fixed_new()); 108 gtk_widget_set_app_paintable(container_, TRUE);
109 g_signal_connect(container_, "expose-event",
110 G_CALLBACK(OnExpose), NULL);
77 111
78 // |fixed_| has to be at least one pixel tall. We color this pixel the same 112 // |fixed_| has to be at least one pixel tall. We color this pixel the same
79 // color as the border that separates the toolbar from the web contents. 113 // color as the border that separates the toolbar from the web contents.
80 // TODO(estade): find a better solution. (Ideally the tool bar shouldn't draw 114 // TODO(estade): find a better solution. (Ideally the tool bar shouldn't draw
81 // its own border, but the border is part of the background bitmap, so 115 // its own border, but the border is part of the background bitmap, so
82 // changing that would affect all platforms.) 116 // changing that would affect all platforms.)
117 fixed_.Own(gtk_fixed_new());
83 border_ = gtk_event_box_new(); 118 border_ = gtk_event_box_new();
84 gtk_widget_set_size_request(border_, 1, 1); 119 gtk_widget_set_size_request(border_, 1, 1);
85 gtk_widget_modify_bg(border_, GTK_STATE_NORMAL, &kBorderColor); 120 gtk_widget_modify_bg(border_, GTK_STATE_NORMAL, &kBorderColor);
86 121
87 gtk_fixed_put(GTK_FIXED(widget()), border_, 0, 0); 122 gtk_fixed_put(GTK_FIXED(widget()), border_, 0, 0);
88 gtk_fixed_put(GTK_FIXED(widget()), container_, 0, kVerticalOffset); 123 gtk_fixed_put(GTK_FIXED(widget()), container_, 0, kVerticalOffset);
89 gtk_widget_set_size_request(widget(), -1, 0); 124 gtk_widget_set_size_request(widget(), -1, 0);
90 125
91 close_button_.reset(CustomDrawButton::AddBarCloseButton(hbox)); 126 close_button_.reset(CustomDrawButton::AddBarCloseButton(hbox));
92 g_signal_connect(G_OBJECT(close_button_->widget()), "clicked", 127 g_signal_connect(G_OBJECT(close_button_->widget()), "clicked",
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 gtk_entry_get_text(GTK_ENTRY(find_bar->find_text_))); 265 gtk_entry_get_text(GTK_ENTRY(find_bar->find_text_)));
231 find_bar->find_bar_controller_->web_contents()->StartFinding( 266 find_bar->find_bar_controller_->web_contents()->StartFinding(
232 UTF8ToUTF16(find_text_utf8), 267 UTF8ToUTF16(find_text_utf8),
233 button == find_bar->find_next_button_->widget()); 268 button == find_bar->find_next_button_->widget());
234 } else { 269 } else {
235 NOTREACHED(); 270 NOTREACHED();
236 } 271 }
237 } 272 }
238 273
239 // static 274 // static
240 void FindBarGtk::OnSizeAllocate(GtkWidget* fixed, 275 void FindBarGtk::OnFixedSizeAllocate(GtkWidget* fixed,
241 GtkAllocation* allocation, 276 GtkAllocation* allocation,
242 FindBarGtk* findbar) { 277 FindBarGtk* findbar) {
243 // Set the background widget to the size of |fixed|. 278 // Set the background widget to the size of |fixed|.
244 if (findbar->border_->allocation.width != allocation->width) { 279 if (findbar->border_->allocation.width != allocation->width) {
245 // Typically it's not a good idea to use this function outside of container 280 // Typically it's not a good idea to use this function outside of container
246 // implementations, but GtkFixed doesn't do any sizing on its children so 281 // implementations, but GtkFixed doesn't do any sizing on its children so
247 // in this case it's safe. 282 // in this case it's safe.
248 gtk_widget_size_allocate(findbar->border_, allocation); 283 gtk_widget_size_allocate(findbar->border_, allocation);
249 } 284 }
250 285
251 // Reposition |container_|. 286 // Reposition |container_|.
252 GtkWidget* container = findbar->container_; 287 GtkWidget* container = findbar->container_;
253 DCHECK(container); 288 DCHECK(container);
254 if (!GTK_WIDGET_VISIBLE(container)) 289 if (!GTK_WIDGET_VISIBLE(container))
255 return; 290 return;
256 291
257 int xposition = findbar->GetDialogPosition(gfx::Rect()).x(); 292 int xposition = findbar->GetDialogPosition(gfx::Rect()).x();
258 if (xposition == container->allocation.x) { 293 if (xposition == container->allocation.x) {
259 return; 294 return;
260 } else { 295 } else {
261 gtk_fixed_move(GTK_FIXED(fixed), container, xposition, kVerticalOffset); 296 gtk_fixed_move(GTK_FIXED(fixed), container, xposition, kVerticalOffset);
262 } 297 }
263 } 298 }
299
300 // static
301 void FindBarGtk::OnContainerSizeAllocate(GtkWidget* container,
302 GtkAllocation* allocation,
303 FindBarGtk* findbar) {
304 if (!findbar->container_shaped_) {
305 GetDialogBackground()->ContourWidget(container);
306 findbar->container_shaped_ = true;
307 }
308 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/find_bar_gtk.h ('k') | chrome/browser/gtk/nine_box.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698