OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 10 |
11 #include "app/gfx/font.h" | 11 #include "app/gfx/font.h" |
12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/gfx/gtk_util.h" | 15 #include "base/gfx/gtk_util.h" |
16 #include "base/gfx/rect.h" | 16 #include "base/gfx/rect.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "chrome/browser/autocomplete/autocomplete.h" | 19 #include "chrome/browser/autocomplete/autocomplete.h" |
20 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 20 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
21 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 21 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
22 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 22 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 23 #include "chrome/browser/bubble_positioner.h" |
23 #include "chrome/browser/defaults.h" | 24 #include "chrome/browser/defaults.h" |
24 #include "chrome/browser/profile.h" | 25 #include "chrome/browser/profile.h" |
25 #include "chrome/browser/search_engines/template_url.h" | 26 #include "chrome/browser/search_engines/template_url.h" |
26 #include "chrome/browser/search_engines/template_url_model.h" | 27 #include "chrome/browser/search_engines/template_url_model.h" |
27 #include "chrome/browser/gtk/rounded_window.h" | 28 #include "chrome/browser/gtk/rounded_window.h" |
28 #include "chrome/common/notification_service.h" | 29 #include "chrome/common/notification_service.h" |
29 #include "grit/theme_resources.h" | 30 #include "grit/theme_resources.h" |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 236 |
236 return NULL; | 237 return NULL; |
237 } | 238 } |
238 | 239 |
239 } // namespace | 240 } // namespace |
240 | 241 |
241 AutocompletePopupViewGtk::AutocompletePopupViewGtk( | 242 AutocompletePopupViewGtk::AutocompletePopupViewGtk( |
242 AutocompleteEditView* edit_view, | 243 AutocompleteEditView* edit_view, |
243 AutocompleteEditModel* edit_model, | 244 AutocompleteEditModel* edit_model, |
244 Profile* profile, | 245 Profile* profile, |
245 AutocompletePopupPositioner* popup_positioner) | 246 const BubblePositioner* bubble_positioner) |
246 : model_(new AutocompletePopupModel(this, edit_model, profile)), | 247 : model_(new AutocompletePopupModel(this, edit_model, profile)), |
247 edit_view_(edit_view), | 248 edit_view_(edit_view), |
248 popup_positioner_(popup_positioner), | 249 bubble_positioner_(bubble_positioner), |
249 window_(gtk_window_new(GTK_WINDOW_POPUP)), | 250 window_(gtk_window_new(GTK_WINDOW_POPUP)), |
250 layout_(NULL), | 251 layout_(NULL), |
251 opened_(false) { | 252 opened_(false) { |
252 GTK_WIDGET_UNSET_FLAGS(window_, GTK_CAN_FOCUS); | 253 GTK_WIDGET_UNSET_FLAGS(window_, GTK_CAN_FOCUS); |
253 // Don't allow the window to be resized. This also forces the window to | 254 // Don't allow the window to be resized. This also forces the window to |
254 // shrink down to the size of its child contents. | 255 // shrink down to the size of its child contents. |
255 gtk_window_set_resizable(GTK_WINDOW(window_), FALSE); | 256 gtk_window_set_resizable(GTK_WINDOW(window_), FALSE); |
256 gtk_widget_set_app_paintable(window_, TRUE); | 257 gtk_widget_set_app_paintable(window_, TRUE); |
257 // Have GTK double buffer around the expose signal. | 258 // Have GTK double buffer around the expose signal. |
258 gtk_widget_set_double_buffered(window_, TRUE); | 259 gtk_widget_set_double_buffered(window_, TRUE); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 void AutocompletePopupViewGtk::PaintUpdatesNow() { | 329 void AutocompletePopupViewGtk::PaintUpdatesNow() { |
329 // Paint our queued invalidations now, synchronously. | 330 // Paint our queued invalidations now, synchronously. |
330 gdk_window_process_updates(window_->window, FALSE); | 331 gdk_window_process_updates(window_->window, FALSE); |
331 } | 332 } |
332 | 333 |
333 AutocompletePopupModel* AutocompletePopupViewGtk::GetModel() { | 334 AutocompletePopupModel* AutocompletePopupViewGtk::GetModel() { |
334 return model_.get(); | 335 return model_.get(); |
335 } | 336 } |
336 | 337 |
337 void AutocompletePopupViewGtk::Show(size_t num_results) { | 338 void AutocompletePopupViewGtk::Show(size_t num_results) { |
338 gfx::Rect rect = popup_positioner_->GetPopupBounds(); | 339 gfx::Rect rect = bubble_positioner_->GetLocationStackBounds(); |
| 340 rect.set_y(rect.bottom()); |
339 rect.set_height((num_results * kHeightPerResult) + (kBorderThickness * 2)); | 341 rect.set_height((num_results * kHeightPerResult) + (kBorderThickness * 2)); |
340 | 342 |
341 gtk_window_move(GTK_WINDOW(window_), rect.x(), rect.y()); | 343 gtk_window_move(GTK_WINDOW(window_), rect.x(), rect.y()); |
342 gtk_widget_set_size_request(window_, rect.width(), rect.height()); | 344 gtk_widget_set_size_request(window_, rect.width(), rect.height()); |
343 gtk_widget_show(window_); | 345 gtk_widget_show(window_); |
344 opened_ = true; | 346 opened_ = true; |
345 } | 347 } |
346 | 348 |
347 void AutocompletePopupViewGtk::Hide() { | 349 void AutocompletePopupViewGtk::Hide() { |
348 gtk_widget_hide(window_); | 350 gtk_widget_hide(window_); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 504 |
503 return FALSE; | 505 return FALSE; |
504 } | 506 } |
505 | 507 |
506 // static | 508 // static |
507 AutocompletePopupView* AutocompletePopupView::CreatePopupView( | 509 AutocompletePopupView* AutocompletePopupView::CreatePopupView( |
508 const gfx::Font& font, | 510 const gfx::Font& font, |
509 AutocompleteEditView* edit_view, | 511 AutocompleteEditView* edit_view, |
510 AutocompleteEditModel* edit_model, | 512 AutocompleteEditModel* edit_model, |
511 Profile* profile, | 513 Profile* profile, |
512 AutocompletePopupPositioner* popup_positioner) { | 514 const BubblePositioner* bubble_positioner) { |
513 return new AutocompletePopupViewGtk(edit_view, edit_model, profile, | 515 return new AutocompletePopupViewGtk(edit_view, edit_model, profile, |
514 popup_positioner); | 516 bubble_positioner); |
515 } | 517 } |
OLD | NEW |