| 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/gfx/gtk_util.h" | 12 #include "app/gfx/gtk_util.h" |
| 13 #include "app/l10n_util.h" | 13 #include "app/l10n_util.h" |
| 14 #include "app/resource_bundle.h" | 14 #include "app/resource_bundle.h" |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.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_gtk.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/bubble_positioner.h" |
| 24 #include "chrome/browser/defaults.h" | 24 #include "chrome/browser/defaults.h" |
| 25 #include "chrome/browser/profile.h" | 25 #include "chrome/browser/profile.h" |
| 26 #include "chrome/browser/search_engines/template_url.h" | 26 #include "chrome/browser/search_engines/template_url.h" |
| 27 #include "chrome/browser/search_engines/template_url_model.h" | 27 #include "chrome/browser/search_engines/template_url_model.h" |
| 28 #include "chrome/common/gtk_util.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 |
| 33 const GdkColor kBorderColor = GDK_COLOR_RGB(0xc7, 0xca, 0xce); | 34 const GdkColor kBorderColor = GDK_COLOR_RGB(0xc7, 0xca, 0xce); |
| 34 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xff, 0xff, 0xff); | 35 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xff, 0xff, 0xff); |
| 35 const GdkColor kSelectedBackgroundColor = GDK_COLOR_RGB(0xdf, 0xe6, 0xf6); | 36 const GdkColor kSelectedBackgroundColor = GDK_COLOR_RGB(0xdf, 0xe6, 0xf6); |
| 36 const GdkColor kHoveredBackgroundColor = GDK_COLOR_RGB(0xef, 0xf2, 0xfa); | 37 const GdkColor kHoveredBackgroundColor = GDK_COLOR_RGB(0xef, 0xf2, 0xfa); |
| 37 | 38 |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 } | 339 } |
| 339 | 340 |
| 340 void AutocompletePopupViewGtk::Show(size_t num_results) { | 341 void AutocompletePopupViewGtk::Show(size_t num_results) { |
| 341 gfx::Rect rect = bubble_positioner_->GetLocationStackBounds(); | 342 gfx::Rect rect = bubble_positioner_->GetLocationStackBounds(); |
| 342 rect.set_y(rect.bottom()); | 343 rect.set_y(rect.bottom()); |
| 343 rect.set_height((num_results * kHeightPerResult) + (kBorderThickness * 2)); | 344 rect.set_height((num_results * kHeightPerResult) + (kBorderThickness * 2)); |
| 344 | 345 |
| 345 gtk_window_move(GTK_WINDOW(window_), rect.x(), rect.y()); | 346 gtk_window_move(GTK_WINDOW(window_), rect.x(), rect.y()); |
| 346 gtk_widget_set_size_request(window_, rect.width(), rect.height()); | 347 gtk_widget_set_size_request(window_, rect.width(), rect.height()); |
| 347 gtk_widget_show(window_); | 348 gtk_widget_show(window_); |
| 349 StackWindow(); |
| 348 opened_ = true; | 350 opened_ = true; |
| 349 } | 351 } |
| 350 | 352 |
| 351 void AutocompletePopupViewGtk::Hide() { | 353 void AutocompletePopupViewGtk::Hide() { |
| 352 gtk_widget_hide(window_); | 354 gtk_widget_hide(window_); |
| 353 opened_ = false; | 355 opened_ = false; |
| 354 } | 356 } |
| 355 | 357 |
| 358 void AutocompletePopupViewGtk::StackWindow() { |
| 359 gfx::NativeView edit_view = edit_view_->GetNativeView(); |
| 360 DCHECK(GTK_IS_WIDGET(edit_view)); |
| 361 GtkWidget* toplevel = gtk_widget_get_toplevel(edit_view); |
| 362 DCHECK(GTK_WIDGET_TOPLEVEL(toplevel)); |
| 363 gtk_util::StackPopupWindow(window_, toplevel); |
| 364 } |
| 365 |
| 356 size_t AutocompletePopupViewGtk::LineFromY(int y) { | 366 size_t AutocompletePopupViewGtk::LineFromY(int y) { |
| 357 size_t line = std::max(y - kBorderThickness, 0) / kHeightPerResult; | 367 size_t line = std::max(y - kBorderThickness, 0) / kHeightPerResult; |
| 358 return std::min(line, model_->result().size() - 1); | 368 return std::min(line, model_->result().size() - 1); |
| 359 } | 369 } |
| 360 | 370 |
| 361 void AutocompletePopupViewGtk::AcceptLine(size_t line, | 371 void AutocompletePopupViewGtk::AcceptLine(size_t line, |
| 362 WindowOpenDisposition disposition) { | 372 WindowOpenDisposition disposition) { |
| 363 const AutocompleteMatch& match = model_->result().match_at(line); | 373 const AutocompleteMatch& match = model_->result().match_at(line); |
| 364 // OpenURL() may close the popup, which will clear the result set and, by | 374 // OpenURL() may close the popup, which will clear the result set and, by |
| 365 // extension, |match| and its contents. So copy the relevant strings out to | 375 // extension, |match| and its contents. So copy the relevant strings out to |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // static | 532 // static |
| 523 AutocompletePopupView* AutocompletePopupView::CreatePopupView( | 533 AutocompletePopupView* AutocompletePopupView::CreatePopupView( |
| 524 const gfx::Font& font, | 534 const gfx::Font& font, |
| 525 AutocompleteEditView* edit_view, | 535 AutocompleteEditView* edit_view, |
| 526 AutocompleteEditModel* edit_model, | 536 AutocompleteEditModel* edit_model, |
| 527 Profile* profile, | 537 Profile* profile, |
| 528 const BubblePositioner* bubble_positioner) { | 538 const BubblePositioner* bubble_positioner) { |
| 529 return new AutocompletePopupViewGtk(edit_view, edit_model, profile, | 539 return new AutocompletePopupViewGtk(edit_view, edit_model, profile, |
| 530 bubble_positioner); | 540 bubble_positioner); |
| 531 } | 541 } |
| OLD | NEW |