Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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/autocomplete/autocomplete_popup_view_gtk.h" | 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete.h" | 17 #include "chrome/browser/autocomplete/autocomplete.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 18 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" | 19 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" |
| 20 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 20 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 21 #include "chrome/browser/bubble_positioner.h" | |
| 22 #include "chrome/browser/defaults.h" | 21 #include "chrome/browser/defaults.h" |
| 23 #include "chrome/browser/gtk/gtk_util.h" | 22 #include "chrome/browser/gtk/gtk_util.h" |
| 24 #include "chrome/browser/profile.h" | 23 #include "chrome/browser/profile.h" |
| 25 #include "chrome/browser/search_engines/template_url.h" | 24 #include "chrome/browser/search_engines/template_url.h" |
| 26 #include "chrome/browser/search_engines/template_url_model.h" | 25 #include "chrome/browser/search_engines/template_url_model.h" |
| 27 #include "chrome/common/notification_service.h" | 26 #include "chrome/common/notification_service.h" |
| 28 #include "gfx/font.h" | 27 #include "gfx/font.h" |
| 29 #include "gfx/gtk_util.h" | 28 #include "gfx/gtk_util.h" |
| 30 #include "gfx/rect.h" | 29 #include "gfx/rect.h" |
| 31 #include "grit/theme_resources.h" | 30 #include "grit/theme_resources.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 // TODO(estade): Do we want to flip these for RTL? (Windows doesn't). | 179 // TODO(estade): Do we want to flip these for RTL? (Windows doesn't). |
| 181 return ResourceBundle::GetSharedInstance().GetPixbufNamed(icon); | 180 return ResourceBundle::GetSharedInstance().GetPixbufNamed(icon); |
| 182 } | 181 } |
| 183 | 182 |
| 184 } // namespace | 183 } // namespace |
| 185 | 184 |
| 186 AutocompletePopupViewGtk::AutocompletePopupViewGtk( | 185 AutocompletePopupViewGtk::AutocompletePopupViewGtk( |
| 187 AutocompleteEditView* edit_view, | 186 AutocompleteEditView* edit_view, |
| 188 AutocompleteEditModel* edit_model, | 187 AutocompleteEditModel* edit_model, |
| 189 Profile* profile, | 188 Profile* profile, |
| 190 const BubblePositioner* bubble_positioner) | 189 const GtkWidget* location_bar) |
| 191 : model_(new AutocompletePopupModel(this, edit_model, profile)), | 190 : model_(new AutocompletePopupModel(this, edit_model, profile)), |
| 192 edit_view_(edit_view), | 191 edit_view_(edit_view), |
| 193 bubble_positioner_(bubble_positioner), | 192 location_bar_(location_bar), |
| 194 window_(gtk_window_new(GTK_WINDOW_POPUP)), | 193 window_(gtk_window_new(GTK_WINDOW_POPUP)), |
| 195 layout_(NULL), | 194 layout_(NULL), |
| 196 opened_(false) { | 195 opened_(false) { |
| 197 GTK_WIDGET_UNSET_FLAGS(window_, GTK_CAN_FOCUS); | 196 GTK_WIDGET_UNSET_FLAGS(window_, GTK_CAN_FOCUS); |
| 198 // Don't allow the window to be resized. This also forces the window to | 197 // Don't allow the window to be resized. This also forces the window to |
| 199 // shrink down to the size of its child contents. | 198 // shrink down to the size of its child contents. |
| 200 gtk_window_set_resizable(GTK_WINDOW(window_), FALSE); | 199 gtk_window_set_resizable(GTK_WINDOW(window_), FALSE); |
| 201 gtk_widget_set_app_paintable(window_, TRUE); | 200 gtk_widget_set_app_paintable(window_, TRUE); |
| 202 // Have GTK double buffer around the expose signal. | 201 // Have GTK double buffer around the expose signal. |
| 203 gtk_widget_set_double_buffered(window_, TRUE); | 202 gtk_widget_set_double_buffered(window_, TRUE); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 void AutocompletePopupViewGtk::PaintUpdatesNow() { | 278 void AutocompletePopupViewGtk::PaintUpdatesNow() { |
| 280 // Paint our queued invalidations now, synchronously. | 279 // Paint our queued invalidations now, synchronously. |
| 281 gdk_window_process_updates(window_->window, FALSE); | 280 gdk_window_process_updates(window_->window, FALSE); |
| 282 } | 281 } |
| 283 | 282 |
| 284 AutocompletePopupModel* AutocompletePopupViewGtk::GetModel() { | 283 AutocompletePopupModel* AutocompletePopupViewGtk::GetModel() { |
| 285 return model_.get(); | 284 return model_.get(); |
| 286 } | 285 } |
| 287 | 286 |
| 288 void AutocompletePopupViewGtk::Show(size_t num_results) { | 287 void AutocompletePopupViewGtk::Show(size_t num_results) { |
| 289 gfx::Rect rect = bubble_positioner_->GetLocationStackBounds(); | 288 gint origin_x, origin_y; |
|
Evan Stade
2010/04/08 22:01:21
nit: indentation
| |
| 290 rect.set_y(rect.bottom()); | 289 gdk_window_get_origin(location_bar_->window, &origin_x, &origin_y); |
| 291 rect.set_height((num_results * kHeightPerResult) + (kBorderThickness * 2)); | 290 const GtkAllocation& allocation = location_bar_->allocation; |
| 292 | 291 gtk_window_move(GTK_WINDOW(window_), |
| 293 gtk_window_move(GTK_WINDOW(window_), rect.x(), rect.y()); | 292 origin_x + allocation.x - kBorderThickness, |
| 294 gtk_widget_set_size_request(window_, rect.width(), rect.height()); | 293 origin_y + allocation.y + allocation.height - kBorderThickness - 1); |
| 294 gtk_widget_set_size_request(window_, allocation.width + (kBorderThickness * 2), | |
| 295 (num_results * kHeightPerResult) + (kBorderThickness * 2)); | |
| 295 gtk_widget_show(window_); | 296 gtk_widget_show(window_); |
| 296 StackWindow(); | 297 StackWindow(); |
| 297 opened_ = true; | 298 opened_ = true; |
| 298 } | 299 } |
| 299 | 300 |
| 300 void AutocompletePopupViewGtk::Hide() { | 301 void AutocompletePopupViewGtk::Hide() { |
| 301 gtk_widget_hide(window_); | 302 gtk_widget_hide(window_); |
| 302 opened_ = false; | 303 opened_ = false; |
| 303 } | 304 } |
| 304 | 305 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 text_width - actual_content_width - | 467 text_width - actual_content_width - |
| 467 actual_description_width / PANGO_SCALE, | 468 actual_description_width / PANGO_SCALE, |
| 468 content_y, layout_); | 469 content_y, layout_); |
| 469 } | 470 } |
| 470 } | 471 } |
| 471 | 472 |
| 472 g_object_unref(gc); | 473 g_object_unref(gc); |
| 473 | 474 |
| 474 return TRUE; | 475 return TRUE; |
| 475 } | 476 } |
| 476 | |
| 477 // static | |
| 478 AutocompletePopupView* AutocompletePopupView::CreatePopupView( | |
| 479 const gfx::Font& font, | |
| 480 AutocompleteEditView* edit_view, | |
| 481 AutocompleteEditModel* edit_model, | |
| 482 Profile* profile, | |
| 483 const BubblePositioner* bubble_positioner) { | |
| 484 return new AutocompletePopupViewGtk(edit_view, edit_model, profile, | |
| 485 bubble_positioner); | |
| 486 } | |
| OLD | NEW |