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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/gtk/find_bar_gtk.cc
diff --git a/chrome/browser/ui/gtk/find_bar_gtk.cc b/chrome/browser/ui/gtk/find_bar_gtk.cc
index f52486279b5fbca025b53b2e0d263e6910fbe706..77389831bba424bde5e57c2c8e06645e28911542 100644
--- a/chrome/browser/ui/gtk/find_bar_gtk.cc
+++ b/chrome/browser/ui/gtk/find_bar_gtk.cc
@@ -271,6 +271,11 @@ void FindBarGtk::InitWidgets() {
GtkWidget* content_hbox = gtk_hbox_new(FALSE, 0);
gtk_widget_set_size_request(content_hbox, kTextEntryWidth, -1);
+ // Connect to the "size-allocate" signal so we can adjust the size downwards
+ // if it ends up being too big for the allocated space.
+ g_signal_connect(content_hbox, "size-allocate",
+ G_CALLBACK(OnContentSizeAllocate), this);
+
text_entry_ = gtk_entry_new();
gtk_entry_set_has_frame(GTK_ENTRY(text_entry_), FALSE);
@@ -419,19 +424,24 @@ void FindBarGtk::AudibleAlert() {
// gtk_widget_error_bell(widget());
}
-gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
+gfx::Rect FindBarGtk::GetDialogBounds() {
bool ltr = !base::i18n::IsRTL();
// 15 is the size of the scrollbar, copied from ScrollbarThemeChromium.
// The height is not used.
// At very low browser widths we can wind up with a negative |dialog_bounds|
// width, so clamp it to 0.
- gfx::Rect dialog_bounds = gfx::Rect(ltr ? 0 : 15, 0,
+ return gfx::Rect(ltr ? 0 : 15, 0,
std::max(0, widget()->parent->allocation.width - (ltr ? 15 : 0)), 0);
+}
+
+gfx::Rect FindBarGtk::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
+ gfx::Rect dialog_bounds = GetDialogBounds();
GtkRequisition req;
gtk_widget_size_request(container_, &req);
gfx::Size prefsize(req.width, req.height);
+ bool ltr = !base::i18n::IsRTL();
gfx::Rect view_location(
ltr ? dialog_bounds.width() - prefsize.width() : dialog_bounds.x(),
dialog_bounds.y(), prefsize.width(), prefsize.height());
@@ -578,6 +588,12 @@ string16 FindBarGtk::GetMatchCountText() {
return UTF8ToUTF16(contents);
}
+int FindBarGtk::GetWidth() {
+ GtkRequisition req;
+ 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
+ return req.width;
+}
+
void FindBarGtk::FindEntryTextInContents(bool forward_search) {
TabContentsWrapper* tab_contents = find_bar_controller_->tab_contents();
if (!tab_contents)
@@ -735,6 +751,22 @@ void FindBarGtk::OnParentSet(GtkWidget* widget, GtkObject* old_parent,
}
// static
+void FindBarGtk::OnContentSizeAllocate(GtkWidget* content_hbox,
+ GtkAllocation* allocation,
+ FindBarGtk* find_bar) {
+ gfx::Rect dialog_bounds = find_bar->GetDialogBounds();
+ GtkRequisition req;
+ gtk_widget_size_request(find_bar->widget(), &req);
+
+ if (req.width > dialog_bounds.width()) {
+ GtkRequisition hbox_req;
+ gtk_widget_size_request(content_hbox, &hbox_req);
+ int new_width = hbox_req.width - (req.width - dialog_bounds.width());
+ 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!
+ }
+}
+
+// static
void FindBarGtk::OnSetFloatingPosition(
GtkFloatingContainer* floating_container,
GtkAllocation* allocation,
« 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