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

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

Issue 7063003: Make FindBar obey dialog bounds for GTK. Will fix other platforms in separate patches. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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/ui/gtk/find_bar_gtk.h ('k') | chrome/browser/ui/views/find_bar_host.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) 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 l10n_util::GetStringUTF8(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP).c_str()); 264 l10n_util::GetStringUTF8(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP).c_str());
265 gtk_box_pack_end(GTK_BOX(hbox), find_previous_button_->widget(), 265 gtk_box_pack_end(GTK_BOX(hbox), find_previous_button_->widget(),
266 FALSE, FALSE, 0); 266 FALSE, FALSE, 0);
267 267
268 // Make a box for the edit and match count widgets. This is fixed size since 268 // Make a box for the edit and match count widgets. This is fixed size since
269 // we want the widgets inside to resize themselves rather than making the 269 // we want the widgets inside to resize themselves rather than making the
270 // dialog bigger. 270 // dialog bigger.
271 GtkWidget* content_hbox = gtk_hbox_new(FALSE, 0); 271 GtkWidget* content_hbox = gtk_hbox_new(FALSE, 0);
272 gtk_widget_set_size_request(content_hbox, kTextEntryWidth, -1); 272 gtk_widget_set_size_request(content_hbox, kTextEntryWidth, -1);
273 273
274 // Connect to the "size-allocate" signal so we can adjust the size downwards
275 // if it ends up being too big for the allocated space.
276 g_signal_connect(content_hbox, "size-allocate",
277 G_CALLBACK(OnContentSizeAllocate), this);
278
274 text_entry_ = gtk_entry_new(); 279 text_entry_ = gtk_entry_new();
275 gtk_entry_set_has_frame(GTK_ENTRY(text_entry_), FALSE); 280 gtk_entry_set_has_frame(GTK_ENTRY(text_entry_), FALSE);
276 281
277 match_count_label_ = gtk_label_new(NULL); 282 match_count_label_ = gtk_label_new(NULL);
278 // This line adds padding on the sides so that the label has even padding on 283 // This line adds padding on the sides so that the label has even padding on
279 // all edges. 284 // all edges.
280 gtk_misc_set_padding(GTK_MISC(match_count_label_), 2, 0); 285 gtk_misc_set_padding(GTK_MISC(match_count_label_), 2, 0);
281 match_count_event_box_ = gtk_event_box_new(); 286 match_count_event_box_ = gtk_event_box_new();
282 GtkWidget* match_count_centerer = gtk_vbox_new(FALSE, 0); 287 GtkWidget* match_count_centerer = gtk_vbox_new(FALSE, 0);
283 gtk_box_pack_start(GTK_BOX(match_count_centerer), match_count_event_box_, 288 gtk_box_pack_start(GTK_BOX(match_count_centerer), match_count_event_box_,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 417 }
413 418
414 void FindBarGtk::AudibleAlert() { 419 void FindBarGtk::AudibleAlert() {
415 // This call causes a lot of weird bugs, especially when using the custom 420 // This call causes a lot of weird bugs, especially when using the custom
416 // frame. TODO(estade): if people complain, re-enable it. See 421 // frame. TODO(estade): if people complain, re-enable it. See
417 // http://crbug.com/27635 and others. 422 // http://crbug.com/27635 and others.
418 // 423 //
419 // gtk_widget_error_bell(widget()); 424 // gtk_widget_error_bell(widget());
420 } 425 }
421 426
422 gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) { 427 gfx::Rect FindBarGtk::GetDialogBounds() {
423 bool ltr = !base::i18n::IsRTL(); 428 bool ltr = !base::i18n::IsRTL();
424 // 15 is the size of the scrollbar, copied from ScrollbarThemeChromium. 429 // 15 is the size of the scrollbar, copied from ScrollbarThemeChromium.
425 // The height is not used. 430 // The height is not used.
426 // At very low browser widths we can wind up with a negative |dialog_bounds| 431 // At very low browser widths we can wind up with a negative |dialog_bounds|
427 // width, so clamp it to 0. 432 // width, so clamp it to 0.
428 gfx::Rect dialog_bounds = gfx::Rect(ltr ? 0 : 15, 0, 433 return gfx::Rect(ltr ? 0 : 15, 0,
429 std::max(0, widget()->parent->allocation.width - (ltr ? 15 : 0)), 0); 434 std::max(0, widget()->parent->allocation.width - (ltr ? 15 : 0)), 0);
435 }
436
437 gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
438 gfx::Rect dialog_bounds = GetDialogBounds();
430 439
431 GtkRequisition req; 440 GtkRequisition req;
432 gtk_widget_size_request(container_, &req); 441 gtk_widget_size_request(container_, &req);
433 gfx::Size prefsize(req.width, req.height); 442 gfx::Size prefsize(req.width, req.height);
434 443
444 bool ltr = !base::i18n::IsRTL();
435 gfx::Rect view_location( 445 gfx::Rect view_location(
436 ltr ? dialog_bounds.width() - prefsize.width() : dialog_bounds.x(), 446 ltr ? dialog_bounds.width() - prefsize.width() : dialog_bounds.x(),
437 dialog_bounds.y(), prefsize.width(), prefsize.height()); 447 dialog_bounds.y(), prefsize.width(), prefsize.height());
438 gfx::Rect new_pos = FindBarController::GetLocationForFindbarView( 448 gfx::Rect new_pos = FindBarController::GetLocationForFindbarView(
439 view_location, dialog_bounds, avoid_overlapping_rect); 449 view_location, dialog_bounds, avoid_overlapping_rect);
440 450
441 return new_pos; 451 return new_pos;
442 } 452 }
443 453
444 bool FindBarGtk::IsFindBarVisible() { 454 bool FindBarGtk::IsFindBarVisible() {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 NULL); 581 NULL);
572 std::string contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); 582 std::string contents(gtk_entry_get_text(GTK_ENTRY(text_entry_)));
573 return UTF8ToUTF16(contents.substr(cursor_pos, selection_bound)); 583 return UTF8ToUTF16(contents.substr(cursor_pos, selection_bound));
574 } 584 }
575 585
576 string16 FindBarGtk::GetMatchCountText() { 586 string16 FindBarGtk::GetMatchCountText() {
577 std::string contents(gtk_label_get_text(GTK_LABEL(match_count_label_))); 587 std::string contents(gtk_label_get_text(GTK_LABEL(match_count_label_)));
578 return UTF8ToUTF16(contents); 588 return UTF8ToUTF16(contents);
579 } 589 }
580 590
591 int FindBarGtk::GetWidth() {
592 GtkRequisition req;
593 gtk_widget_size_request(container_, &req);
Evan Stade 2011/05/23 19:29:15 perhaps a note here about why you are returning th
jennb 2011/05/24 01:05:37 Changed to use allocation. I didn't know about it
594 return req.width;
595 }
596
581 void FindBarGtk::FindEntryTextInContents(bool forward_search) { 597 void FindBarGtk::FindEntryTextInContents(bool forward_search) {
582 TabContentsWrapper* tab_contents = find_bar_controller_->tab_contents(); 598 TabContentsWrapper* tab_contents = find_bar_controller_->tab_contents();
583 if (!tab_contents) 599 if (!tab_contents)
584 return; 600 return;
585 FindTabHelper* find_tab_helper = tab_contents->find_tab_helper(); 601 FindTabHelper* find_tab_helper = tab_contents->find_tab_helper();
586 602
587 std::string new_contents(gtk_entry_get_text(GTK_ENTRY(text_entry_))); 603 std::string new_contents(gtk_entry_get_text(GTK_ENTRY(text_entry_)));
588 604
589 if (new_contents.length() > 0) { 605 if (new_contents.length() > 0) {
590 find_tab_helper->StartFinding(UTF8ToUTF16(new_contents), forward_search, 606 find_tab_helper->StartFinding(UTF8ToUTF16(new_contents), forward_search,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 void FindBarGtk::OnParentSet(GtkWidget* widget, GtkObject* old_parent, 744 void FindBarGtk::OnParentSet(GtkWidget* widget, GtkObject* old_parent,
729 FindBarGtk* find_bar) { 745 FindBarGtk* find_bar) {
730 if (!widget->parent) 746 if (!widget->parent)
731 return; 747 return;
732 748
733 g_signal_connect(widget->parent, "set-floating-position", 749 g_signal_connect(widget->parent, "set-floating-position",
734 G_CALLBACK(OnSetFloatingPosition), find_bar); 750 G_CALLBACK(OnSetFloatingPosition), find_bar);
735 } 751 }
736 752
737 // static 753 // static
754 void FindBarGtk::OnContentSizeAllocate(GtkWidget* content_hbox,
755 GtkAllocation* allocation,
756 FindBarGtk* find_bar) {
757 gfx::Rect dialog_bounds = find_bar->GetDialogBounds();
758 GtkRequisition req;
759 gtk_widget_size_request(find_bar->widget(), &req);
760
761 if (req.width > dialog_bounds.width()) {
762 GtkRequisition hbox_req;
763 gtk_widget_size_request(content_hbox, &hbox_req);
764 int new_width = hbox_req.width - (req.width - dialog_bounds.width());
765 gtk_widget_set_size_request(content_hbox, new_width, -1);
Evan Stade 2011/05/23 19:29:15 technically you aren't supposed to change your req
jennb 2011/05/24 01:05:37 Good tip. Thanks!
766 }
767 }
768
769 // static
738 void FindBarGtk::OnSetFloatingPosition( 770 void FindBarGtk::OnSetFloatingPosition(
739 GtkFloatingContainer* floating_container, 771 GtkFloatingContainer* floating_container,
740 GtkAllocation* allocation, 772 GtkAllocation* allocation,
741 FindBarGtk* find_bar) { 773 FindBarGtk* find_bar) {
742 GtkWidget* findbar = find_bar->widget(); 774 GtkWidget* findbar = find_bar->widget();
743 775
744 int xposition = find_bar->GetDialogPosition(find_bar->selection_rect_).x(); 776 int xposition = find_bar->GetDialogPosition(find_bar->selection_rect_).x();
745 777
746 GValue value = { 0, }; 778 GValue value = { 0, };
747 g_value_init(&value, G_TYPE_INT); 779 g_value_init(&value, G_TYPE_INT);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 1018
987 // static 1019 // static
988 gboolean FindBarGtk::OnFocusOut(GtkWidget* entry, GdkEventFocus* event, 1020 gboolean FindBarGtk::OnFocusOut(GtkWidget* entry, GdkEventFocus* event,
989 FindBarGtk* find_bar) { 1021 FindBarGtk* find_bar) {
990 g_signal_handlers_disconnect_by_func( 1022 g_signal_handlers_disconnect_by_func(
991 gdk_keymap_get_for_display(gtk_widget_get_display(entry)), 1023 gdk_keymap_get_for_display(gtk_widget_get_display(entry)),
992 reinterpret_cast<gpointer>(&OnKeymapDirectionChanged), find_bar); 1024 reinterpret_cast<gpointer>(&OnKeymapDirectionChanged), find_bar);
993 1025
994 return FALSE; // Continue propagation. 1026 return FALSE; // Continue propagation.
995 } 1027 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/find_bar_gtk.h ('k') | chrome/browser/ui/views/find_bar_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698