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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 // | 415 // |
416 // gtk_widget_error_bell(widget()); | 416 // gtk_widget_error_bell(widget()); |
417 } | 417 } |
418 | 418 |
419 gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) { | 419 gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) { |
420 bool ltr = !base::i18n::IsRTL(); | 420 bool ltr = !base::i18n::IsRTL(); |
421 // 15 is the size of the scrollbar, copied from ScrollbarThemeChromium. | 421 // 15 is the size of the scrollbar, copied from ScrollbarThemeChromium. |
422 // The height is not used. | 422 // The height is not used. |
423 // At very low browser widths we can wind up with a negative |dialog_bounds| | 423 // At very low browser widths we can wind up with a negative |dialog_bounds| |
424 // width, so clamp it to 0. | 424 // width, so clamp it to 0. |
| 425 GtkAllocation parent_allocation; |
| 426 gtk_widget_get_allocation(gtk_widget_get_parent(widget()), |
| 427 &parent_allocation); |
425 gfx::Rect dialog_bounds = gfx::Rect(ltr ? 0 : 15, 0, | 428 gfx::Rect dialog_bounds = gfx::Rect(ltr ? 0 : 15, 0, |
426 std::max(0, widget()->parent->allocation.width - (ltr ? 15 : 0)), 0); | 429 std::max(0, parent_allocation.width - (ltr ? 15 : 0)), 0); |
427 | 430 |
428 GtkRequisition req; | 431 GtkRequisition req; |
429 gtk_widget_size_request(container_, &req); | 432 gtk_widget_size_request(container_, &req); |
430 gfx::Size prefsize(req.width, req.height); | 433 gfx::Size prefsize(req.width, req.height); |
431 | 434 |
432 gfx::Rect view_location( | 435 gfx::Rect view_location( |
433 ltr ? dialog_bounds.width() - prefsize.width() : dialog_bounds.x(), | 436 ltr ? dialog_bounds.width() - prefsize.width() : dialog_bounds.x(), |
434 dialog_bounds.y(), prefsize.width(), prefsize.height()); | 437 dialog_bounds.y(), prefsize.width(), prefsize.height()); |
435 gfx::Rect new_pos = FindBarController::GetLocationForFindbarView( | 438 gfx::Rect new_pos = FindBarController::GetLocationForFindbarView( |
436 view_location, dialog_bounds, avoid_overlapping_rect); | 439 view_location, dialog_bounds, avoid_overlapping_rect); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 std::string contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); | 571 std::string contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); |
569 return UTF8ToUTF16(contents.substr(cursor_pos, selection_bound)); | 572 return UTF8ToUTF16(contents.substr(cursor_pos, selection_bound)); |
570 } | 573 } |
571 | 574 |
572 string16 FindBarGtk::GetMatchCountText() { | 575 string16 FindBarGtk::GetMatchCountText() { |
573 std::string contents(gtk_label_get_text(GTK_LABEL(match_count_label_))); | 576 std::string contents(gtk_label_get_text(GTK_LABEL(match_count_label_))); |
574 return UTF8ToUTF16(contents); | 577 return UTF8ToUTF16(contents); |
575 } | 578 } |
576 | 579 |
577 int FindBarGtk::GetWidth() { | 580 int FindBarGtk::GetWidth() { |
578 return container_->allocation.width; | 581 GtkAllocation allocation; |
| 582 gtk_widget_get_allocation(container_, &allocation); |
| 583 return allocation.width; |
579 } | 584 } |
580 | 585 |
581 void FindBarGtk::FindEntryTextInContents(bool forward_search) { | 586 void FindBarGtk::FindEntryTextInContents(bool forward_search) { |
582 TabContentsWrapper* tab_contents = find_bar_controller_->tab_contents(); | 587 TabContentsWrapper* tab_contents = find_bar_controller_->tab_contents(); |
583 if (!tab_contents) | 588 if (!tab_contents) |
584 return; | 589 return; |
585 FindTabHelper* find_tab_helper = tab_contents->find_tab_helper(); | 590 FindTabHelper* find_tab_helper = tab_contents->find_tab_helper(); |
586 | 591 |
587 std::string new_contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); | 592 std::string new_contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); |
588 | 593 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 return FALSE; // Continue propagation. | 980 return FALSE; // Continue propagation. |
976 } | 981 } |
977 | 982 |
978 gboolean FindBarGtk::OnFocusOut(GtkWidget* entry, GdkEventFocus* event) { | 983 gboolean FindBarGtk::OnFocusOut(GtkWidget* entry, GdkEventFocus* event) { |
979 g_signal_handlers_disconnect_by_func( | 984 g_signal_handlers_disconnect_by_func( |
980 gdk_keymap_get_for_display(gtk_widget_get_display(entry)), | 985 gdk_keymap_get_for_display(gtk_widget_get_display(entry)), |
981 reinterpret_cast<gpointer>(&OnKeymapDirectionChanged), this); | 986 reinterpret_cast<gpointer>(&OnKeymapDirectionChanged), this); |
982 | 987 |
983 return FALSE; // Continue propagation. | 988 return FALSE; // Continue propagation. |
984 } | 989 } |
OLD | NEW |