| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/gtk/find_bar_gtk.h" | |
| 6 | |
| 7 #include <gdk/gdkkeysyms.h> | |
| 8 | |
| 9 #include <algorithm> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "app/l10n_util.h" | |
| 14 #include "app/resource_bundle.h" | |
| 15 #include "base/i18n/rtl.h" | |
| 16 #include "base/string_number_conversions.h" | |
| 17 #include "base/string_util.h" | |
| 18 #include "base/utf_string_conversions.h" | |
| 19 #include "chrome/browser/gtk/browser_window_gtk.h" | |
| 20 #include "chrome/browser/gtk/cairo_cached_surface.h" | |
| 21 #include "chrome/browser/gtk/custom_button.h" | |
| 22 #include "chrome/browser/gtk/gtk_floating_container.h" | |
| 23 #include "chrome/browser/gtk/gtk_theme_provider.h" | |
| 24 #include "chrome/browser/gtk/gtk_util.h" | |
| 25 #include "chrome/browser/gtk/nine_box.h" | |
| 26 #include "chrome/browser/gtk/slide_animator_gtk.h" | |
| 27 #include "chrome/browser/gtk/tab_contents_container_gtk.h" | |
| 28 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" | |
| 29 #include "chrome/browser/gtk/view_id_util.h" | |
| 30 #include "chrome/browser/profiles/profile.h" | |
| 31 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 32 #include "chrome/browser/tab_contents/tab_contents.h" | |
| 33 #include "chrome/browser/ui/browser.h" | |
| 34 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | |
| 35 #include "chrome/browser/ui/find_bar/find_bar_state.h" | |
| 36 #include "chrome/common/native_web_keyboard_event.h" | |
| 37 #include "chrome/common/notification_service.h" | |
| 38 #include "grit/generated_resources.h" | |
| 39 #include "grit/theme_resources.h" | |
| 40 | |
| 41 namespace { | |
| 42 | |
| 43 // Used as the color of the text in the entry box and the text for the results | |
| 44 // label for failure searches. | |
| 45 const GdkColor kEntryTextColor = gtk_util::kGdkBlack; | |
| 46 | |
| 47 // Used as the color of the background of the entry box and the background of | |
| 48 // the find label for successful searches. | |
| 49 const GdkColor kEntryBackgroundColor = gtk_util::kGdkWhite; | |
| 50 const GdkColor kFindFailureBackgroundColor = GDK_COLOR_RGB(255, 102, 102); | |
| 51 const GdkColor kFindSuccessTextColor = GDK_COLOR_RGB(178, 178, 178); | |
| 52 | |
| 53 // Padding around the container. | |
| 54 const int kBarPaddingTopBottom = 4; | |
| 55 const int kEntryPaddingLeft = 6; | |
| 56 const int kCloseButtonPaddingLeft = 3; | |
| 57 const int kBarPaddingRight = 4; | |
| 58 | |
| 59 // The height of the findbar dialog, as dictated by the size of the background | |
| 60 // images. | |
| 61 const int kFindBarHeight = 32; | |
| 62 | |
| 63 // The width of the text entry field. | |
| 64 const int kTextEntryWidth = 220; | |
| 65 | |
| 66 // The size of the "rounded" corners. | |
| 67 const int kCornerSize = 3; | |
| 68 | |
| 69 enum FrameType { | |
| 70 FRAME_MASK, | |
| 71 FRAME_STROKE, | |
| 72 }; | |
| 73 | |
| 74 // Returns a list of points that either form the outline of the status bubble | |
| 75 // (|type| == FRAME_MASK) or form the inner border around the inner edge | |
| 76 // (|type| == FRAME_STROKE). | |
| 77 std::vector<GdkPoint> MakeFramePolygonPoints(int width, | |
| 78 int height, | |
| 79 FrameType type) { | |
| 80 using gtk_util::MakeBidiGdkPoint; | |
| 81 std::vector<GdkPoint> points; | |
| 82 | |
| 83 bool ltr = !base::i18n::IsRTL(); | |
| 84 // If we have a stroke, we have to offset some of our points by 1 pixel. | |
| 85 // We have to inset by 1 pixel when we draw horizontal lines that are on the | |
| 86 // bottom or when we draw vertical lines that are closer to the end (end is | |
| 87 // right for ltr). | |
| 88 int y_off = (type == FRAME_MASK) ? 0 : -1; | |
| 89 // We use this one for LTR. | |
| 90 int x_off_l = ltr ? y_off : 0; | |
| 91 // We use this one for RTL. | |
| 92 int x_off_r = !ltr ? -y_off : 0; | |
| 93 | |
| 94 // Top left corner | |
| 95 points.push_back(MakeBidiGdkPoint(x_off_r, 0, width, ltr)); | |
| 96 points.push_back(MakeBidiGdkPoint( | |
| 97 kCornerSize + x_off_r, kCornerSize, width, ltr)); | |
| 98 | |
| 99 // Bottom left corner | |
| 100 points.push_back(MakeBidiGdkPoint( | |
| 101 kCornerSize + x_off_r, height - kCornerSize, width, ltr)); | |
| 102 points.push_back(MakeBidiGdkPoint( | |
| 103 (2 * kCornerSize) + x_off_l, height + y_off, | |
| 104 width, ltr)); | |
| 105 | |
| 106 // Bottom right corner | |
| 107 points.push_back(MakeBidiGdkPoint( | |
| 108 width - (2 * kCornerSize) + x_off_r, height + y_off, | |
| 109 width, ltr)); | |
| 110 points.push_back(MakeBidiGdkPoint( | |
| 111 width - kCornerSize + x_off_l, height - kCornerSize, width, ltr)); | |
| 112 | |
| 113 // Top right corner | |
| 114 points.push_back(MakeBidiGdkPoint( | |
| 115 width - kCornerSize + x_off_l, kCornerSize, width, ltr)); | |
| 116 points.push_back(MakeBidiGdkPoint(width + x_off_l, 0, width, ltr)); | |
| 117 | |
| 118 return points; | |
| 119 } | |
| 120 | |
| 121 // Give the findbar dialog its unique shape using images. | |
| 122 void SetDialogShape(GtkWidget* widget) { | |
| 123 static NineBox* dialog_shape = NULL; | |
| 124 if (!dialog_shape) { | |
| 125 dialog_shape = new NineBox( | |
| 126 IDR_FIND_DLG_LEFT_BACKGROUND, | |
| 127 IDR_FIND_DLG_MIDDLE_BACKGROUND, | |
| 128 IDR_FIND_DLG_RIGHT_BACKGROUND, | |
| 129 0, 0, 0, 0, 0, 0); | |
| 130 dialog_shape->ChangeWhiteToTransparent(); | |
| 131 } | |
| 132 | |
| 133 dialog_shape->ContourWidget(widget); | |
| 134 } | |
| 135 | |
| 136 // Return a ninebox that will paint the border of the findbar dialog. This is | |
| 137 // shared across all instances of the findbar. Do not free the returned pointer. | |
| 138 const NineBox* GetDialogBorder() { | |
| 139 static NineBox* dialog_border = NULL; | |
| 140 if (!dialog_border) { | |
| 141 dialog_border = new NineBox( | |
| 142 IDR_FIND_DIALOG_LEFT, | |
| 143 IDR_FIND_DIALOG_MIDDLE, | |
| 144 IDR_FIND_DIALOG_RIGHT, | |
| 145 0, 0, 0, 0, 0, 0); | |
| 146 } | |
| 147 | |
| 148 return dialog_border; | |
| 149 } | |
| 150 | |
| 151 // Like gtk_util::CreateGtkBorderBin, but allows control over the alignment and | |
| 152 // returns both the event box and the alignment so we can modify it during its | |
| 153 // lifetime (i.e. during a theme change). | |
| 154 void BuildBorder(GtkWidget* child, | |
| 155 bool center, | |
| 156 int padding_top, int padding_bottom, int padding_left, | |
| 157 int padding_right, | |
| 158 GtkWidget** ebox, GtkWidget** alignment) { | |
| 159 *ebox = gtk_event_box_new(); | |
| 160 if (center) | |
| 161 *alignment = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); | |
| 162 else | |
| 163 *alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | |
| 164 gtk_alignment_set_padding(GTK_ALIGNMENT(*alignment), | |
| 165 padding_top, padding_bottom, padding_left, | |
| 166 padding_right); | |
| 167 gtk_container_add(GTK_CONTAINER(*alignment), child); | |
| 168 gtk_container_add(GTK_CONTAINER(*ebox), *alignment); | |
| 169 } | |
| 170 | |
| 171 } // namespace | |
| 172 | |
| 173 FindBarGtk::FindBarGtk(Browser* browser) | |
| 174 : browser_(browser), | |
| 175 window_(static_cast<BrowserWindowGtk*>(browser->window())), | |
| 176 theme_provider_(GtkThemeProvider::GetFrom(browser->profile())), | |
| 177 container_width_(-1), | |
| 178 container_height_(-1), | |
| 179 match_label_failure_(false), | |
| 180 ignore_changed_signal_(false) { | |
| 181 InitWidgets(); | |
| 182 ViewIDUtil::SetID(text_entry_, VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); | |
| 183 | |
| 184 // Insert the widget into the browser gtk hierarchy. | |
| 185 window_->AddFindBar(this); | |
| 186 | |
| 187 // Hook up signals after the widget has been added to the hierarchy so the | |
| 188 // widget will be realized. | |
| 189 g_signal_connect(text_entry_, "changed", | |
| 190 G_CALLBACK(OnChanged), this); | |
| 191 g_signal_connect_after(text_entry_, "key-press-event", | |
| 192 G_CALLBACK(OnKeyPressEvent), this); | |
| 193 g_signal_connect_after(text_entry_, "key-release-event", | |
| 194 G_CALLBACK(OnKeyReleaseEvent), this); | |
| 195 // When the user tabs to us or clicks on us, save where the focus used to | |
| 196 // be. | |
| 197 g_signal_connect(text_entry_, "focus", | |
| 198 G_CALLBACK(OnFocus), this); | |
| 199 gtk_widget_add_events(text_entry_, GDK_BUTTON_PRESS_MASK); | |
| 200 g_signal_connect(text_entry_, "button-press-event", | |
| 201 G_CALLBACK(OnButtonPress), this); | |
| 202 g_signal_connect(text_entry_, "move-cursor", G_CALLBACK(OnMoveCursor), this); | |
| 203 g_signal_connect(text_entry_, "activate", G_CALLBACK(OnActivate), this); | |
| 204 g_signal_connect(text_entry_, "direction-changed", | |
| 205 G_CALLBACK(OnWidgetDirectionChanged), this); | |
| 206 g_signal_connect(text_entry_, "focus-in-event", | |
| 207 G_CALLBACK(OnFocusIn), this); | |
| 208 g_signal_connect(text_entry_, "focus-out-event", | |
| 209 G_CALLBACK(OnFocusOut), this); | |
| 210 g_signal_connect(container_, "expose-event", | |
| 211 G_CALLBACK(OnExpose), this); | |
| 212 } | |
| 213 | |
| 214 FindBarGtk::~FindBarGtk() { | |
| 215 } | |
| 216 | |
| 217 void FindBarGtk::InitWidgets() { | |
| 218 // The find bar is basically an hbox with a gtkentry (text box) followed by 3 | |
| 219 // buttons (previous result, next result, close). We wrap the hbox in a gtk | |
| 220 // alignment and a gtk event box to get the padding and light blue | |
| 221 // background. We put that event box in a fixed in order to control its | |
| 222 // lateral position. We put that fixed in a SlideAnimatorGtk in order to get | |
| 223 // the slide effect. | |
| 224 GtkWidget* hbox = gtk_hbox_new(false, 0); | |
| 225 container_ = gtk_util::CreateGtkBorderBin(hbox, NULL, | |
| 226 kBarPaddingTopBottom, kBarPaddingTopBottom, | |
| 227 kEntryPaddingLeft, kBarPaddingRight); | |
| 228 ViewIDUtil::SetID(container_, VIEW_ID_FIND_IN_PAGE); | |
| 229 gtk_widget_set_app_paintable(container_, TRUE); | |
| 230 | |
| 231 slide_widget_.reset(new SlideAnimatorGtk(container_, | |
| 232 SlideAnimatorGtk::DOWN, | |
| 233 0, false, false, NULL)); | |
| 234 | |
| 235 close_button_.reset(CustomDrawButton::CloseButton(theme_provider_)); | |
| 236 gtk_util::CenterWidgetInHBox(hbox, close_button_->widget(), true, | |
| 237 kCloseButtonPaddingLeft); | |
| 238 g_signal_connect(close_button_->widget(), "clicked", | |
| 239 G_CALLBACK(OnClicked), this); | |
| 240 gtk_widget_set_tooltip_text(close_button_->widget(), | |
| 241 l10n_util::GetStringUTF8(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP).c_str()); | |
| 242 | |
| 243 find_next_button_.reset(new CustomDrawButton(theme_provider_, | |
| 244 IDR_FINDINPAGE_NEXT, IDR_FINDINPAGE_NEXT_H, IDR_FINDINPAGE_NEXT_H, | |
| 245 IDR_FINDINPAGE_NEXT_P, GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_MENU)); | |
| 246 g_signal_connect(find_next_button_->widget(), "clicked", | |
| 247 G_CALLBACK(OnClicked), this); | |
| 248 gtk_widget_set_tooltip_text(find_next_button_->widget(), | |
| 249 l10n_util::GetStringUTF8(IDS_FIND_IN_PAGE_NEXT_TOOLTIP).c_str()); | |
| 250 gtk_box_pack_end(GTK_BOX(hbox), find_next_button_->widget(), | |
| 251 FALSE, FALSE, 0); | |
| 252 | |
| 253 find_previous_button_.reset(new CustomDrawButton(theme_provider_, | |
| 254 IDR_FINDINPAGE_PREV, IDR_FINDINPAGE_PREV_H, IDR_FINDINPAGE_PREV_H, | |
| 255 IDR_FINDINPAGE_PREV_P, GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU)); | |
| 256 g_signal_connect(find_previous_button_->widget(), "clicked", | |
| 257 G_CALLBACK(OnClicked), this); | |
| 258 gtk_widget_set_tooltip_text(find_previous_button_->widget(), | |
| 259 l10n_util::GetStringUTF8(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP).c_str()); | |
| 260 gtk_box_pack_end(GTK_BOX(hbox), find_previous_button_->widget(), | |
| 261 FALSE, FALSE, 0); | |
| 262 | |
| 263 // Make a box for the edit and match count widgets. This is fixed size since | |
| 264 // we want the widgets inside to resize themselves rather than making the | |
| 265 // dialog bigger. | |
| 266 GtkWidget* content_hbox = gtk_hbox_new(FALSE, 0); | |
| 267 gtk_widget_set_size_request(content_hbox, kTextEntryWidth, -1); | |
| 268 | |
| 269 text_entry_ = gtk_entry_new(); | |
| 270 gtk_entry_set_has_frame(GTK_ENTRY(text_entry_), FALSE); | |
| 271 | |
| 272 match_count_label_ = gtk_label_new(NULL); | |
| 273 // This line adds padding on the sides so that the label has even padding on | |
| 274 // all edges. | |
| 275 gtk_misc_set_padding(GTK_MISC(match_count_label_), 2, 0); | |
| 276 match_count_event_box_ = gtk_event_box_new(); | |
| 277 GtkWidget* match_count_centerer = gtk_vbox_new(FALSE, 0); | |
| 278 gtk_box_pack_start(GTK_BOX(match_count_centerer), match_count_event_box_, | |
| 279 TRUE, TRUE, 0); | |
| 280 gtk_container_set_border_width(GTK_CONTAINER(match_count_centerer), 1); | |
| 281 gtk_container_add(GTK_CONTAINER(match_count_event_box_), match_count_label_); | |
| 282 | |
| 283 gtk_box_pack_end(GTK_BOX(content_hbox), match_count_centerer, | |
| 284 FALSE, FALSE, 0); | |
| 285 gtk_box_pack_end(GTK_BOX(content_hbox), text_entry_, TRUE, TRUE, 0); | |
| 286 | |
| 287 // This event box is necessary to color in the area above and below the match | |
| 288 // count label, and is where we draw the entry background onto in GTK mode. | |
| 289 BuildBorder(content_hbox, true, 0, 0, 0, 0, | |
| 290 &content_event_box_, &content_alignment_); | |
| 291 gtk_widget_set_app_paintable(content_event_box_, TRUE); | |
| 292 g_signal_connect(content_event_box_, "expose-event", | |
| 293 G_CALLBACK(OnContentEventBoxExpose), this); | |
| 294 | |
| 295 // This alignment isn't centered and is used for spacing in chrome theme | |
| 296 // mode. (It's also used in GTK mode for padding because left padding doesn't | |
| 297 // equal bottom padding naturally.) | |
| 298 BuildBorder(content_event_box_, false, 2, 2, 2, 0, | |
| 299 &border_bin_, &border_bin_alignment_); | |
| 300 gtk_util::CenterWidgetInHBox(hbox, border_bin_, true, 0); | |
| 301 | |
| 302 theme_provider_->InitThemesFor(this); | |
| 303 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | |
| 304 NotificationService::AllSources()); | |
| 305 | |
| 306 g_signal_connect(widget(), "parent-set", G_CALLBACK(OnParentSet), this); | |
| 307 | |
| 308 // We take care to avoid showing the slide animator widget. | |
| 309 gtk_widget_show_all(container_); | |
| 310 gtk_widget_show(widget()); | |
| 311 } | |
| 312 | |
| 313 FindBarController* FindBarGtk::GetFindBarController() const { | |
| 314 return find_bar_controller_; | |
| 315 } | |
| 316 | |
| 317 void FindBarGtk::SetFindBarController(FindBarController* find_bar_controller) { | |
| 318 find_bar_controller_ = find_bar_controller; | |
| 319 } | |
| 320 | |
| 321 void FindBarGtk::Show(bool animate) { | |
| 322 if (animate) { | |
| 323 slide_widget_->Open(); | |
| 324 selection_rect_ = gfx::Rect(); | |
| 325 Reposition(); | |
| 326 if (container_->window) | |
| 327 gdk_window_raise(container_->window); | |
| 328 } else { | |
| 329 slide_widget_->OpenWithoutAnimation(); | |
| 330 } | |
| 331 } | |
| 332 | |
| 333 void FindBarGtk::Hide(bool animate) { | |
| 334 if (animate) | |
| 335 slide_widget_->Close(); | |
| 336 else | |
| 337 slide_widget_->CloseWithoutAnimation(); | |
| 338 } | |
| 339 | |
| 340 void FindBarGtk::SetFocusAndSelection() { | |
| 341 StoreOutsideFocus(); | |
| 342 gtk_widget_grab_focus(text_entry_); | |
| 343 // Select all the text. | |
| 344 gtk_entry_select_region(GTK_ENTRY(text_entry_), 0, -1); | |
| 345 } | |
| 346 | |
| 347 void FindBarGtk::ClearResults(const FindNotificationDetails& results) { | |
| 348 UpdateUIForFindResult(results, string16()); | |
| 349 } | |
| 350 | |
| 351 void FindBarGtk::StopAnimation() { | |
| 352 slide_widget_->End(); | |
| 353 } | |
| 354 | |
| 355 void FindBarGtk::MoveWindowIfNecessary(const gfx::Rect& selection_rect, | |
| 356 bool no_redraw) { | |
| 357 // Not moving the window on demand, so do nothing. | |
| 358 } | |
| 359 | |
| 360 void FindBarGtk::SetFindText(const string16& find_text) { | |
| 361 std::string find_text_utf8 = UTF16ToUTF8(find_text); | |
| 362 | |
| 363 // Ignore the "changed" signal handler because programatically setting the | |
| 364 // text should not fire a "changed" event. | |
| 365 ignore_changed_signal_ = true; | |
| 366 gtk_entry_set_text(GTK_ENTRY(text_entry_), find_text_utf8.c_str()); | |
| 367 ignore_changed_signal_ = false; | |
| 368 } | |
| 369 | |
| 370 void FindBarGtk::UpdateUIForFindResult(const FindNotificationDetails& result, | |
| 371 const string16& find_text) { | |
| 372 if (!result.selection_rect().IsEmpty()) { | |
| 373 selection_rect_ = result.selection_rect(); | |
| 374 int xposition = GetDialogPosition(result.selection_rect()).x(); | |
| 375 if (xposition != widget()->allocation.x) | |
| 376 Reposition(); | |
| 377 } | |
| 378 | |
| 379 // 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. | |
| 381 if (result.number_of_matches() > 0) | |
| 382 focus_store_.Store(NULL); | |
| 383 | |
| 384 std::string find_text_utf8 = UTF16ToUTF8(find_text); | |
| 385 bool have_valid_range = | |
| 386 result.number_of_matches() != -1 && result.active_match_ordinal() != -1; | |
| 387 | |
| 388 std::string entry_text(gtk_entry_get_text(GTK_ENTRY(text_entry_))); | |
| 389 if (entry_text != find_text_utf8) { | |
| 390 SetFindText(find_text); | |
| 391 gtk_entry_select_region(GTK_ENTRY(text_entry_), 0, -1); | |
| 392 } | |
| 393 | |
| 394 if (!find_text.empty() && have_valid_range) { | |
| 395 gtk_label_set_text(GTK_LABEL(match_count_label_), | |
| 396 l10n_util::GetStringFUTF8(IDS_FIND_IN_PAGE_COUNT, | |
| 397 base::IntToString16(result.active_match_ordinal()), | |
| 398 base::IntToString16(result.number_of_matches())).c_str()); | |
| 399 UpdateMatchLabelAppearance(result.number_of_matches() == 0 && | |
| 400 result.final_update()); | |
| 401 } else { | |
| 402 // If there was no text entered, we don't show anything in the result count | |
| 403 // area. | |
| 404 gtk_label_set_text(GTK_LABEL(match_count_label_), ""); | |
| 405 UpdateMatchLabelAppearance(false); | |
| 406 } | |
| 407 } | |
| 408 | |
| 409 void FindBarGtk::AudibleAlert() { | |
| 410 // This call causes a lot of weird bugs, especially when using the custom | |
| 411 // frame. TODO(estade): if people complain, re-enable it. See | |
| 412 // http://crbug.com/27635 and others. | |
| 413 // | |
| 414 // gtk_widget_error_bell(widget()); | |
| 415 } | |
| 416 | |
| 417 gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) { | |
| 418 bool ltr = !base::i18n::IsRTL(); | |
| 419 // 15 is the size of the scrollbar, copied from ScrollbarThemeChromium. | |
| 420 // The height is not used. | |
| 421 // At very low browser widths we can wind up with a negative |dialog_bounds| | |
| 422 // width, so clamp it to 0. | |
| 423 gfx::Rect dialog_bounds = gfx::Rect(ltr ? 0 : 15, 0, | |
| 424 std::max(0, widget()->parent->allocation.width - (ltr ? 15 : 0)), 0); | |
| 425 | |
| 426 GtkRequisition req; | |
| 427 gtk_widget_size_request(container_, &req); | |
| 428 gfx::Size prefsize(req.width, req.height); | |
| 429 | |
| 430 gfx::Rect view_location( | |
| 431 ltr ? dialog_bounds.width() - prefsize.width() : dialog_bounds.x(), | |
| 432 dialog_bounds.y(), prefsize.width(), prefsize.height()); | |
| 433 gfx::Rect new_pos = FindBarController::GetLocationForFindbarView( | |
| 434 view_location, dialog_bounds, avoid_overlapping_rect); | |
| 435 | |
| 436 return new_pos; | |
| 437 } | |
| 438 | |
| 439 bool FindBarGtk::IsFindBarVisible() { | |
| 440 return GTK_WIDGET_VISIBLE(widget()); | |
| 441 } | |
| 442 | |
| 443 void FindBarGtk::RestoreSavedFocus() { | |
| 444 // This function sometimes gets called when we don't have focus. We should do | |
| 445 // nothing in this case. | |
| 446 if (!gtk_widget_is_focus(text_entry_)) | |
| 447 return; | |
| 448 | |
| 449 if (focus_store_.widget()) | |
| 450 gtk_widget_grab_focus(focus_store_.widget()); | |
| 451 else | |
| 452 find_bar_controller_->tab_contents()->Focus(); | |
| 453 } | |
| 454 | |
| 455 FindBarTesting* FindBarGtk::GetFindBarTesting() { | |
| 456 return this; | |
| 457 } | |
| 458 | |
| 459 void FindBarGtk::Observe(NotificationType type, | |
| 460 const NotificationSource& source, | |
| 461 const NotificationDetails& details) { | |
| 462 DCHECK_EQ(type.value, NotificationType::BROWSER_THEME_CHANGED); | |
| 463 | |
| 464 // Force reshapings of the find bar window. | |
| 465 container_width_ = -1; | |
| 466 container_height_ = -1; | |
| 467 | |
| 468 if (theme_provider_->UseGtkTheme()) { | |
| 469 gtk_widget_modify_cursor(text_entry_, NULL, NULL); | |
| 470 gtk_widget_modify_base(text_entry_, GTK_STATE_NORMAL, NULL); | |
| 471 gtk_widget_modify_text(text_entry_, GTK_STATE_NORMAL, NULL); | |
| 472 | |
| 473 // Prevent forced font sizes because it causes the jump up and down | |
| 474 // character movement (http://crbug.com/22614), and because it will | |
| 475 // prevent centering of the text entry. | |
| 476 gtk_util::UndoForceFontSize(text_entry_); | |
| 477 gtk_util::UndoForceFontSize(match_count_label_); | |
| 478 | |
| 479 gtk_widget_set_size_request(content_event_box_, -1, -1); | |
| 480 gtk_widget_modify_bg(content_event_box_, GTK_STATE_NORMAL, NULL); | |
| 481 | |
| 482 // Replicate the normal GtkEntry behaviour by drawing the entry | |
| 483 // background. We set the fake alignment to be the frame thickness. | |
| 484 GtkStyle* style = gtk_rc_get_style(text_entry_); | |
| 485 gint xborder = style->xthickness; | |
| 486 gint yborder = style->ythickness; | |
| 487 gtk_alignment_set_padding(GTK_ALIGNMENT(content_alignment_), | |
| 488 yborder, yborder, xborder, xborder); | |
| 489 | |
| 490 // We leave left padding on the left, even in GTK mode, as it's required | |
| 491 // for the left margin to be equivalent to the bottom margin. | |
| 492 gtk_alignment_set_padding(GTK_ALIGNMENT(border_bin_alignment_), | |
| 493 0, 0, 1, 0); | |
| 494 | |
| 495 // We need this event box to have its own window in GTK mode for doing the | |
| 496 // hacky widget rendering. | |
| 497 gtk_event_box_set_visible_window(GTK_EVENT_BOX(border_bin_), TRUE); | |
| 498 gtk_widget_set_app_paintable(border_bin_, TRUE); | |
| 499 | |
| 500 gtk_misc_set_alignment(GTK_MISC(match_count_label_), 0.5, 0.5); | |
| 501 } else { | |
| 502 gtk_widget_modify_cursor( | |
| 503 text_entry_, >k_util::kGdkBlack, >k_util::kGdkGray); | |
| 504 gtk_widget_modify_base(text_entry_, GTK_STATE_NORMAL, | |
| 505 &kEntryBackgroundColor); | |
| 506 gtk_widget_modify_text(text_entry_, GTK_STATE_NORMAL, | |
| 507 &kEntryTextColor); | |
| 508 | |
| 509 // Until we switch to vector graphics, force the font size. | |
| 510 gtk_util::ForceFontSizePixels(text_entry_, 13.4); // 13.4px == 10pt @ 96dpi | |
| 511 gtk_util::ForceFontSizePixels(match_count_label_, 13.4); | |
| 512 | |
| 513 // Force the text widget height so it lines up with the buttons regardless | |
| 514 // of font size. | |
| 515 gtk_widget_set_size_request(content_event_box_, -1, 20); | |
| 516 gtk_widget_modify_bg(content_event_box_, GTK_STATE_NORMAL, | |
| 517 &kEntryBackgroundColor); | |
| 518 | |
| 519 gtk_alignment_set_padding(GTK_ALIGNMENT(content_alignment_), | |
| 520 0.0, 0.0, 0.0, 0.0); | |
| 521 | |
| 522 gtk_alignment_set_padding(GTK_ALIGNMENT(border_bin_alignment_), | |
| 523 2, 2, 3, 0); | |
| 524 | |
| 525 // We need this event box to be invisible because we're only going to draw | |
| 526 // on the background (but we can't take it out of the heiarchy entirely | |
| 527 // because we also need it to take up space). | |
| 528 gtk_event_box_set_visible_window(GTK_EVENT_BOX(border_bin_), FALSE); | |
| 529 gtk_widget_set_app_paintable(border_bin_, FALSE); | |
| 530 | |
| 531 gtk_misc_set_alignment(GTK_MISC(match_count_label_), 0.5, 1.0); | |
| 532 | |
| 533 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 534 close_button_->SetBackground( | |
| 535 theme_provider_->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT), | |
| 536 rb.GetBitmapNamed(IDR_CLOSE_BAR), | |
| 537 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); | |
| 538 } | |
| 539 | |
| 540 UpdateMatchLabelAppearance(match_label_failure_); | |
| 541 } | |
| 542 | |
| 543 bool FindBarGtk::GetFindBarWindowInfo(gfx::Point* position, | |
| 544 bool* fully_visible) { | |
| 545 if (position) | |
| 546 *position = GetPosition(); | |
| 547 | |
| 548 if (fully_visible) { | |
| 549 *fully_visible = !slide_widget_->IsAnimating() && | |
| 550 slide_widget_->IsShowing(); | |
| 551 } | |
| 552 return true; | |
| 553 } | |
| 554 | |
| 555 string16 FindBarGtk::GetFindText() { | |
| 556 std::string contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); | |
| 557 return UTF8ToUTF16(contents); | |
| 558 } | |
| 559 | |
| 560 string16 FindBarGtk::GetFindSelectedText() { | |
| 561 gint cursor_pos; | |
| 562 gint selection_bound; | |
| 563 g_object_get(G_OBJECT(text_entry_), "cursor-position", &cursor_pos, | |
| 564 NULL); | |
| 565 g_object_get(G_OBJECT(text_entry_), "selection-bound", &selection_bound, | |
| 566 NULL); | |
| 567 std::string contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); | |
| 568 return UTF8ToUTF16(contents.substr(cursor_pos, selection_bound)); | |
| 569 } | |
| 570 | |
| 571 string16 FindBarGtk::GetMatchCountText() { | |
| 572 std::string contents(gtk_label_get_text(GTK_LABEL(match_count_label_))); | |
| 573 return UTF8ToUTF16(contents); | |
| 574 } | |
| 575 | |
| 576 void FindBarGtk::FindEntryTextInContents(bool forward_search) { | |
| 577 TabContents* tab_contents = find_bar_controller_->tab_contents(); | |
| 578 if (!tab_contents) | |
| 579 return; | |
| 580 | |
| 581 std::string new_contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); | |
| 582 | |
| 583 if (new_contents.length() > 0) { | |
| 584 tab_contents->StartFinding(UTF8ToUTF16(new_contents), forward_search, | |
| 585 false); // Not case sensitive. | |
| 586 } else { | |
| 587 // The textbox is empty so we reset. | |
| 588 tab_contents->StopFinding(FindBarController::kClearSelection); | |
| 589 UpdateUIForFindResult(find_bar_controller_->tab_contents()->find_result(), | |
| 590 string16()); | |
| 591 | |
| 592 // Clearing the text box should also clear the prepopulate state so that | |
| 593 // when we close and reopen the Find box it doesn't show the search we | |
| 594 // just deleted. | |
| 595 FindBarState* find_bar_state = browser_->profile()->GetFindBarState(); | |
| 596 find_bar_state->set_last_prepopulate_text(string16()); | |
| 597 } | |
| 598 } | |
| 599 | |
| 600 void FindBarGtk::UpdateMatchLabelAppearance(bool failure) { | |
| 601 match_label_failure_ = failure; | |
| 602 bool use_gtk = theme_provider_->UseGtkTheme(); | |
| 603 | |
| 604 if (use_gtk) { | |
| 605 GtkStyle* style = gtk_rc_get_style(text_entry_); | |
| 606 GdkColor normal_bg = style->base[GTK_STATE_NORMAL]; | |
| 607 GdkColor normal_text = gtk_util::AverageColors( | |
| 608 style->text[GTK_STATE_NORMAL], style->base[GTK_STATE_NORMAL]); | |
| 609 | |
| 610 gtk_widget_modify_bg(match_count_event_box_, GTK_STATE_NORMAL, | |
| 611 failure ? &kFindFailureBackgroundColor : | |
| 612 &normal_bg); | |
| 613 gtk_widget_modify_fg(match_count_label_, GTK_STATE_NORMAL, | |
| 614 failure ? &kEntryTextColor : &normal_text); | |
| 615 } else { | |
| 616 gtk_widget_modify_bg(match_count_event_box_, GTK_STATE_NORMAL, | |
| 617 failure ? &kFindFailureBackgroundColor : | |
| 618 &kEntryBackgroundColor); | |
| 619 gtk_widget_modify_fg(match_count_label_, GTK_STATE_NORMAL, | |
| 620 failure ? &kEntryTextColor : &kFindSuccessTextColor); | |
| 621 } | |
| 622 } | |
| 623 | |
| 624 void FindBarGtk::Reposition() { | |
| 625 if (!IsFindBarVisible()) | |
| 626 return; | |
| 627 | |
| 628 // This will trigger an allocate, which allows us to reposition. | |
| 629 if (widget()->parent) | |
| 630 gtk_widget_queue_resize(widget()->parent); | |
| 631 } | |
| 632 | |
| 633 void FindBarGtk::StoreOutsideFocus() { | |
| 634 // |text_entry_| is the only widget in the find bar that can be focused, | |
| 635 // so it's the only one we have to check. | |
| 636 // TODO(estade): when we make the find bar buttons focusable, we'll have | |
| 637 // to change this (same above in RestoreSavedFocus). | |
| 638 if (!gtk_widget_is_focus(text_entry_)) | |
| 639 focus_store_.Store(text_entry_); | |
| 640 } | |
| 641 | |
| 642 bool FindBarGtk::MaybeForwardKeyEventToRenderer(GdkEventKey* event) { | |
| 643 switch (event->keyval) { | |
| 644 case GDK_Down: | |
| 645 case GDK_Up: | |
| 646 case GDK_Page_Up: | |
| 647 case GDK_Page_Down: | |
| 648 break; | |
| 649 case GDK_Home: | |
| 650 case GDK_End: | |
| 651 if ((event->state & gtk_accelerator_get_default_mod_mask()) == | |
| 652 GDK_CONTROL_MASK) { | |
| 653 break; | |
| 654 } | |
| 655 // Fall through. | |
| 656 default: | |
| 657 return false; | |
| 658 } | |
| 659 | |
| 660 TabContents* contents = find_bar_controller_->tab_contents(); | |
| 661 if (!contents) | |
| 662 return false; | |
| 663 | |
| 664 RenderViewHost* render_view_host = contents->render_view_host(); | |
| 665 | |
| 666 // Make sure we don't have a text field element interfering with keyboard | |
| 667 // input. Otherwise Up and Down arrow key strokes get eaten. "Nom Nom Nom". | |
| 668 render_view_host->ClearFocusedNode(); | |
| 669 | |
| 670 NativeWebKeyboardEvent wke(event); | |
| 671 render_view_host->ForwardKeyboardEvent(wke); | |
| 672 return true; | |
| 673 } | |
| 674 | |
| 675 void FindBarGtk::AdjustTextAlignment() { | |
| 676 PangoDirection content_dir = | |
| 677 pango_find_base_dir(gtk_entry_get_text(GTK_ENTRY(text_entry_)), -1); | |
| 678 | |
| 679 GtkTextDirection widget_dir = gtk_widget_get_direction(text_entry_); | |
| 680 | |
| 681 // Use keymap or widget direction if content does not have strong direction. | |
| 682 // It matches the behavior of GtkEntry. | |
| 683 if (content_dir == PANGO_DIRECTION_NEUTRAL) { | |
| 684 if (GTK_WIDGET_HAS_FOCUS(text_entry_)) { | |
| 685 content_dir = gdk_keymap_get_direction( | |
| 686 gdk_keymap_get_for_display(gtk_widget_get_display(text_entry_))); | |
| 687 } else { | |
| 688 if (widget_dir == GTK_TEXT_DIR_RTL) | |
| 689 content_dir = PANGO_DIRECTION_RTL; | |
| 690 else | |
| 691 content_dir = PANGO_DIRECTION_LTR; | |
| 692 } | |
| 693 } | |
| 694 | |
| 695 if ((widget_dir == GTK_TEXT_DIR_RTL && content_dir == PANGO_DIRECTION_LTR) || | |
| 696 (widget_dir == GTK_TEXT_DIR_LTR && content_dir == PANGO_DIRECTION_RTL)) { | |
| 697 gtk_entry_set_alignment(GTK_ENTRY(text_entry_), 1.0); | |
| 698 } else { | |
| 699 gtk_entry_set_alignment(GTK_ENTRY(text_entry_), 0.0); | |
| 700 } | |
| 701 } | |
| 702 | |
| 703 gfx::Point FindBarGtk::GetPosition() { | |
| 704 gfx::Point point; | |
| 705 | |
| 706 GValue value = { 0, }; | |
| 707 g_value_init(&value, G_TYPE_INT); | |
| 708 gtk_container_child_get_property(GTK_CONTAINER(widget()->parent), | |
| 709 widget(), "x", &value); | |
| 710 point.set_x(g_value_get_int(&value)); | |
| 711 | |
| 712 gtk_container_child_get_property(GTK_CONTAINER(widget()->parent), | |
| 713 widget(), "y", &value); | |
| 714 point.set_y(g_value_get_int(&value)); | |
| 715 | |
| 716 g_value_unset(&value); | |
| 717 | |
| 718 return point; | |
| 719 } | |
| 720 | |
| 721 // static | |
| 722 void FindBarGtk::OnParentSet(GtkWidget* widget, GtkObject* old_parent, | |
| 723 FindBarGtk* find_bar) { | |
| 724 if (!widget->parent) | |
| 725 return; | |
| 726 | |
| 727 g_signal_connect(widget->parent, "set-floating-position", | |
| 728 G_CALLBACK(OnSetFloatingPosition), find_bar); | |
| 729 } | |
| 730 | |
| 731 // static | |
| 732 void FindBarGtk::OnSetFloatingPosition( | |
| 733 GtkFloatingContainer* floating_container, | |
| 734 GtkAllocation* allocation, | |
| 735 FindBarGtk* find_bar) { | |
| 736 GtkWidget* findbar = find_bar->widget(); | |
| 737 | |
| 738 int xposition = find_bar->GetDialogPosition(find_bar->selection_rect_).x(); | |
| 739 | |
| 740 GValue value = { 0, }; | |
| 741 g_value_init(&value, G_TYPE_INT); | |
| 742 g_value_set_int(&value, xposition); | |
| 743 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | |
| 744 findbar, "x", &value); | |
| 745 | |
| 746 g_value_set_int(&value, 0); | |
| 747 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | |
| 748 findbar, "y", &value); | |
| 749 g_value_unset(&value); | |
| 750 } | |
| 751 | |
| 752 // static | |
| 753 gboolean FindBarGtk::OnChanged(GtkWindow* window, FindBarGtk* find_bar) { | |
| 754 find_bar->AdjustTextAlignment(); | |
| 755 | |
| 756 if (!find_bar->ignore_changed_signal_) | |
| 757 find_bar->FindEntryTextInContents(true); | |
| 758 | |
| 759 return FALSE; | |
| 760 } | |
| 761 | |
| 762 // static | |
| 763 gboolean FindBarGtk::OnKeyPressEvent(GtkWidget* widget, GdkEventKey* event, | |
| 764 FindBarGtk* find_bar) { | |
| 765 if (find_bar->MaybeForwardKeyEventToRenderer(event)) { | |
| 766 return TRUE; | |
| 767 } else if (GDK_Escape == event->keyval) { | |
| 768 find_bar->find_bar_controller_->EndFindSession( | |
| 769 FindBarController::kKeepSelection); | |
| 770 return TRUE; | |
| 771 } else if (GDK_Return == event->keyval || | |
| 772 GDK_KP_Enter == event->keyval) { | |
| 773 if ((event->state & gtk_accelerator_get_default_mod_mask()) == | |
| 774 GDK_CONTROL_MASK) { | |
| 775 find_bar->find_bar_controller_->EndFindSession( | |
| 776 FindBarController::kActivateSelection); | |
| 777 return TRUE; | |
| 778 } | |
| 779 | |
| 780 bool forward = (event->state & gtk_accelerator_get_default_mod_mask()) != | |
| 781 GDK_SHIFT_MASK; | |
| 782 find_bar->FindEntryTextInContents(forward); | |
| 783 return TRUE; | |
| 784 } | |
| 785 return FALSE; | |
| 786 } | |
| 787 | |
| 788 // static | |
| 789 gboolean FindBarGtk::OnKeyReleaseEvent(GtkWidget* widget, GdkEventKey* event, | |
| 790 FindBarGtk* find_bar) { | |
| 791 return find_bar->MaybeForwardKeyEventToRenderer(event); | |
| 792 } | |
| 793 | |
| 794 // static | |
| 795 void FindBarGtk::OnClicked(GtkWidget* button, FindBarGtk* find_bar) { | |
| 796 if (button == find_bar->close_button_->widget()) { | |
| 797 find_bar->find_bar_controller_->EndFindSession( | |
| 798 FindBarController::kKeepSelection); | |
| 799 } else if (button == find_bar->find_previous_button_->widget() || | |
| 800 button == find_bar->find_next_button_->widget()) { | |
| 801 find_bar->FindEntryTextInContents( | |
| 802 button == find_bar->find_next_button_->widget()); | |
| 803 } else { | |
| 804 NOTREACHED(); | |
| 805 } | |
| 806 } | |
| 807 | |
| 808 // static | |
| 809 gboolean FindBarGtk::OnContentEventBoxExpose(GtkWidget* widget, | |
| 810 GdkEventExpose* event, | |
| 811 FindBarGtk* bar) { | |
| 812 if (bar->theme_provider_->UseGtkTheme()) { | |
| 813 // Draw the text entry background around where we input stuff. Note the | |
| 814 // decrement to |width|. We do this because some theme engines | |
| 815 // (*cough*Clearlooks*cough*) don't do any blending and use thickness to | |
| 816 // make sure that widgets never overlap. | |
| 817 int padding = gtk_widget_get_style(widget)->xthickness; | |
| 818 GdkRectangle rec = { | |
| 819 widget->allocation.x, | |
| 820 widget->allocation.y, | |
| 821 widget->allocation.width - padding, | |
| 822 widget->allocation.height | |
| 823 }; | |
| 824 | |
| 825 gtk_util::DrawTextEntryBackground(bar->text_entry_, widget, | |
| 826 &event->area, &rec); | |
| 827 } | |
| 828 | |
| 829 return FALSE; | |
| 830 } | |
| 831 | |
| 832 // Used to handle custom painting of |container_|. | |
| 833 gboolean FindBarGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e, | |
| 834 FindBarGtk* bar) { | |
| 835 GtkRequisition req; | |
| 836 gtk_widget_size_request(widget, &req); | |
| 837 gtk_widget_set_size_request(bar->widget(), req.width, -1); | |
| 838 | |
| 839 if (bar->theme_provider_->UseGtkTheme()) { | |
| 840 if (bar->container_width_ != widget->allocation.width || | |
| 841 bar->container_height_ != widget->allocation.height) { | |
| 842 std::vector<GdkPoint> mask_points = MakeFramePolygonPoints( | |
| 843 widget->allocation.width, widget->allocation.height, FRAME_MASK); | |
| 844 GdkRegion* mask_region = gdk_region_polygon(&mask_points[0], | |
| 845 mask_points.size(), | |
| 846 GDK_EVEN_ODD_RULE); | |
| 847 // Reset the shape. | |
| 848 gdk_window_shape_combine_region(widget->window, NULL, 0, 0); | |
| 849 gdk_window_shape_combine_region(widget->window, mask_region, 0, 0); | |
| 850 gdk_region_destroy(mask_region); | |
| 851 | |
| 852 bar->container_width_ = widget->allocation.width; | |
| 853 bar->container_height_ = widget->allocation.height; | |
| 854 } | |
| 855 | |
| 856 GdkDrawable* drawable = GDK_DRAWABLE(e->window); | |
| 857 GdkGC* gc = gdk_gc_new(drawable); | |
| 858 gdk_gc_set_clip_rectangle(gc, &e->area); | |
| 859 GdkColor color = bar->theme_provider_->GetBorderColor(); | |
| 860 gdk_gc_set_rgb_fg_color(gc, &color); | |
| 861 | |
| 862 // Stroke the frame border. | |
| 863 std::vector<GdkPoint> points = MakeFramePolygonPoints( | |
| 864 widget->allocation.width, widget->allocation.height, FRAME_STROKE); | |
| 865 gdk_draw_lines(drawable, gc, &points[0], points.size()); | |
| 866 | |
| 867 g_object_unref(gc); | |
| 868 } else { | |
| 869 if (bar->container_width_ != widget->allocation.width || | |
| 870 bar->container_height_ != widget->allocation.height) { | |
| 871 // Reset the shape. | |
| 872 gdk_window_shape_combine_region(widget->window, NULL, 0, 0); | |
| 873 SetDialogShape(bar->container_); | |
| 874 | |
| 875 bar->container_width_ = widget->allocation.width; | |
| 876 bar->container_height_ = widget->allocation.height; | |
| 877 } | |
| 878 | |
| 879 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | |
| 880 gdk_cairo_rectangle(cr, &e->area); | |
| 881 cairo_clip(cr); | |
| 882 | |
| 883 gfx::Point tabstrip_origin = | |
| 884 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); | |
| 885 | |
| 886 gtk_util::DrawThemedToolbarBackground(widget, cr, e, tabstrip_origin, | |
| 887 bar->theme_provider_); | |
| 888 | |
| 889 // During chrome theme mode, we need to draw the border around content_hbox | |
| 890 // now instead of when we render |border_bin_|. We don't use stacked event | |
| 891 // boxes to simulate the effect because we need to blend them with this | |
| 892 // background. | |
| 893 GtkAllocation border_allocation = bar->border_bin_->allocation; | |
| 894 | |
| 895 // Blit the left part of the background image once on the left. | |
| 896 CairoCachedSurface* background_left = | |
| 897 bar->theme_provider_->GetRTLEnabledSurfaceNamed( | |
| 898 IDR_FIND_BOX_BACKGROUND_LEFT, widget); | |
| 899 background_left->SetSource(cr, border_allocation.x, border_allocation.y); | |
| 900 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | |
| 901 cairo_rectangle(cr, border_allocation.x, border_allocation.y, | |
| 902 background_left->Width(), background_left->Height()); | |
| 903 cairo_fill(cr); | |
| 904 | |
| 905 // Blit the center part of the background image in all the space between. | |
| 906 CairoCachedSurface* background = bar->theme_provider_->GetSurfaceNamed( | |
| 907 IDR_FIND_BOX_BACKGROUND, widget); | |
| 908 background->SetSource(cr, | |
| 909 border_allocation.x + background_left->Width(), | |
| 910 border_allocation.y); | |
| 911 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | |
| 912 cairo_rectangle(cr, | |
| 913 border_allocation.x + background_left->Width(), | |
| 914 border_allocation.y, | |
| 915 border_allocation.width - background_left->Width(), | |
| 916 background->Height()); | |
| 917 cairo_fill(cr); | |
| 918 | |
| 919 cairo_destroy(cr); | |
| 920 | |
| 921 // Draw the border. | |
| 922 GetDialogBorder()->RenderToWidget(widget); | |
| 923 } | |
| 924 | |
| 925 // Propagate to the container's child. | |
| 926 GtkWidget* child = gtk_bin_get_child(GTK_BIN(widget)); | |
| 927 if (child) | |
| 928 gtk_container_propagate_expose(GTK_CONTAINER(widget), child, e); | |
| 929 return TRUE; | |
| 930 } | |
| 931 | |
| 932 // static | |
| 933 gboolean FindBarGtk::OnFocus(GtkWidget* text_entry, GtkDirectionType focus, | |
| 934 FindBarGtk* find_bar) { | |
| 935 find_bar->StoreOutsideFocus(); | |
| 936 | |
| 937 // Continue propagating the event. | |
| 938 return FALSE; | |
| 939 } | |
| 940 | |
| 941 // static | |
| 942 gboolean FindBarGtk::OnButtonPress(GtkWidget* text_entry, GdkEventButton* e, | |
| 943 FindBarGtk* find_bar) { | |
| 944 find_bar->StoreOutsideFocus(); | |
| 945 | |
| 946 // Continue propagating the event. | |
| 947 return FALSE; | |
| 948 } | |
| 949 | |
| 950 // static | |
| 951 void FindBarGtk::OnMoveCursor(GtkEntry* entry, GtkMovementStep step, gint count, | |
| 952 gboolean selection, FindBarGtk* bar) { | |
| 953 static guint signal_id = g_signal_lookup("move-cursor", GTK_TYPE_ENTRY); | |
| 954 | |
| 955 GdkEvent* event = gtk_get_current_event(); | |
| 956 if (event) { | |
| 957 if ((event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE) && | |
| 958 bar->MaybeForwardKeyEventToRenderer(&(event->key))) { | |
| 959 g_signal_stop_emission(entry, signal_id, 0); | |
| 960 } | |
| 961 | |
| 962 gdk_event_free(event); | |
| 963 } | |
| 964 } | |
| 965 | |
| 966 // static | |
| 967 void FindBarGtk::OnActivate(GtkEntry* entry, FindBarGtk* bar) { | |
| 968 bar->FindEntryTextInContents(true); | |
| 969 } | |
| 970 | |
| 971 // static | |
| 972 gboolean FindBarGtk::OnFocusIn(GtkWidget* entry, GdkEventFocus* event, | |
| 973 FindBarGtk* find_bar) { | |
| 974 g_signal_connect( | |
| 975 gdk_keymap_get_for_display(gtk_widget_get_display(entry)), | |
| 976 "direction-changed", | |
| 977 G_CALLBACK(&OnKeymapDirectionChanged), find_bar); | |
| 978 | |
| 979 find_bar->AdjustTextAlignment(); | |
| 980 | |
| 981 return FALSE; // Continue propagation. | |
| 982 } | |
| 983 | |
| 984 // static | |
| 985 gboolean FindBarGtk::OnFocusOut(GtkWidget* entry, GdkEventFocus* event, | |
| 986 FindBarGtk* find_bar) { | |
| 987 g_signal_handlers_disconnect_by_func( | |
| 988 gdk_keymap_get_for_display(gtk_widget_get_display(entry)), | |
| 989 reinterpret_cast<gpointer>(&OnKeymapDirectionChanged), find_bar); | |
| 990 | |
| 991 return FALSE; // Continue propagation. | |
| 992 } | |
| OLD | NEW |