Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc |
| diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc |
| index 911775e6d88818344476a6b87eaace05daae5bd9..a495971f4f4135448d36bcb4e4976ec2c979e0d8 100644 |
| --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc |
| +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc |
| @@ -38,12 +38,14 @@ |
| #include "third_party/undoview/undo_view.h" |
| #if defined(TOOLKIT_VIEWS) |
| -#include "chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h" |
| -#include "chrome/browser/views/location_bar/location_bar_view.h" |
| +#include "chrome/browser/gtk/accessible_widget_helper_gtk.h" |
| +#include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h" |
| +#include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| #else |
| #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
| #include "chrome/browser/gtk/gtk_theme_provider.h" |
| #include "chrome/browser/gtk/location_bar_view_gtk.h" |
| +#include "views/controls/native/native_view_host.h" |
| #endif |
| namespace { |
| @@ -418,44 +420,6 @@ void AutocompleteEditViewGtk::SetFocus() { |
| gtk_widget_grab_focus(text_view_); |
| } |
| -int AutocompleteEditViewGtk::TextWidth() { |
| - int horizontal_border_size = |
| - gtk_text_view_get_border_window_size(GTK_TEXT_VIEW(text_view_), |
| - GTK_TEXT_WINDOW_LEFT) + |
| - gtk_text_view_get_border_window_size(GTK_TEXT_VIEW(text_view_), |
| - GTK_TEXT_WINDOW_RIGHT) + |
| - gtk_text_view_get_left_margin(GTK_TEXT_VIEW(text_view_)) + |
| - gtk_text_view_get_right_margin(GTK_TEXT_VIEW(text_view_)); |
| - |
| - GtkTextIter start, end; |
| - GdkRectangle first_char_bounds, last_char_bounds; |
| - gtk_text_buffer_get_start_iter(text_buffer_, &start); |
| - |
| - // Use the real end iterator here to take the width of instant suggestion |
| - // text into account, so that location bar can layout its children correctly. |
| - gtk_text_buffer_get_end_iter(text_buffer_, &end); |
| - gtk_text_view_get_iter_location(GTK_TEXT_VIEW(text_view_), |
| - &start, &first_char_bounds); |
| - gtk_text_view_get_iter_location(GTK_TEXT_VIEW(text_view_), |
| - &end, &last_char_bounds); |
| - |
| - gint first_char_start = first_char_bounds.x; |
| - gint first_char_end = first_char_start + first_char_bounds.width; |
| - gint last_char_start = last_char_bounds.x; |
| - gint last_char_end = last_char_start + last_char_bounds.width; |
| - |
| - // bounds width could be negative for RTL text. |
| - if (first_char_start > first_char_end) |
| - std::swap(first_char_start, first_char_end); |
| - if (last_char_start > last_char_end) |
| - std::swap(last_char_start, last_char_end); |
| - |
| - gint text_width = first_char_start < last_char_start ? |
| - last_char_end - first_char_start : first_char_end - last_char_start; |
| - |
| - return text_width + horizontal_border_size; |
| -} |
| - |
| int AutocompleteEditViewGtk::WidthOfTextAfterCursor() { |
| // Not used. |
| return -1; |
| @@ -790,6 +754,101 @@ CommandUpdater* AutocompleteEditViewGtk::GetCommandUpdater() { |
| return command_updater_; |
| } |
| +int AutocompleteEditViewGtk::TextWidth() const { |
| + int horizontal_border_size = |
| + gtk_text_view_get_border_window_size(GTK_TEXT_VIEW(text_view_), |
| + GTK_TEXT_WINDOW_LEFT) + |
| + gtk_text_view_get_border_window_size(GTK_TEXT_VIEW(text_view_), |
| + GTK_TEXT_WINDOW_RIGHT) + |
| + gtk_text_view_get_left_margin(GTK_TEXT_VIEW(text_view_)) + |
| + gtk_text_view_get_right_margin(GTK_TEXT_VIEW(text_view_)); |
| + |
| + GtkTextIter start, end; |
| + GdkRectangle first_char_bounds, last_char_bounds; |
| + gtk_text_buffer_get_start_iter(text_buffer_, &start); |
| + |
| + // Use the real end iterator here to take the width of instant suggestion |
| + // text into account, so that location bar can layout its children correctly. |
| + gtk_text_buffer_get_end_iter(text_buffer_, &end); |
| + gtk_text_view_get_iter_location(GTK_TEXT_VIEW(text_view_), |
| + &start, &first_char_bounds); |
| + gtk_text_view_get_iter_location(GTK_TEXT_VIEW(text_view_), |
| + &end, &last_char_bounds); |
| + |
| + gint first_char_start = first_char_bounds.x; |
| + gint first_char_end = first_char_start + first_char_bounds.width; |
| + gint last_char_start = last_char_bounds.x; |
| + gint last_char_end = last_char_start + last_char_bounds.width; |
| + |
| + // bounds width could be negative for RTL text. |
| + if (first_char_start > first_char_end) |
| + std::swap(first_char_start, first_char_end); |
| + if (last_char_start > last_char_end) |
| + std::swap(last_char_start, last_char_end); |
| + |
| + gint text_width = first_char_start < last_char_start ? |
| + last_char_end - first_char_start : first_char_end - last_char_start; |
| + |
| + return text_width + horizontal_border_size; |
| +} |
| + |
| +#if defined(TOOLKIT_VIEWS) |
| +views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) { |
|
Peter Kasting
2011/01/06 02:06:48
Nit: This function is the same in Windows and Gtk.
oshima
2011/01/06 19:43:35
Views implementation will be different (there will
Peter Kasting
2011/01/06 20:51:38
I'm fine with whatever route you want to do as lon
|
| + views::NativeViewHost* host = new views::NativeViewHost; |
| + parent->AddChildView(host); |
| + host->set_focus_view(parent); |
| + host->Attach(GetNativeView()); |
| + return host; |
| +} |
| + |
| +bool AutocompleteEditViewGtk::CommitInstantSuggestion( |
| + const std::wstring& typed_text, |
| + const std::wstring& suggestion) { |
| + return CommitInstantSuggestion(); |
|
Peter Kasting
2011/01/06 02:06:48
Nit: Can't the body of that function be rolled int
oshima
2011/01/06 19:43:35
CommitInstantSuggestoni() is used by gtk version.
Peter Kasting
2011/01/06 20:51:38
OK, but since this ignores its args anyway, couldn
oshima
2011/01/06 21:39:26
Let me refactor further before making this change.
|
| +} |
| + |
| +void AutocompleteEditViewGtk::CreateAccessibleWidgetHelper(int res) { |
| + accessible_widget_helper_.reset( |
| + new AccessibleWidgetHelper(text_view(), model_->profile())); |
| + accessible_widget_helper_->SetWidgetName( |
| + text_view(), l10n_util::GetStringUTF8(res)); |
| +} |
| + |
| +void AutocompleteEditViewGtk::SetInstantSuggestion(const string16& suggestion) { |
| + SetInstantSuggestion(UTF16ToUTF8(suggestion)); |
| +} |
| + |
| +// static |
| +AutocompleteEditView* AutocompleteEditViewGtk::Create( |
| + AutocompleteEditController* controller, |
| + ToolbarModel* toolbar_model, |
| + Profile* profile, |
| + CommandUpdater* command_updater, |
| + bool popup_window_mode, |
| + const views::View* location_bar) { |
| + AutocompleteEditViewGtk* autocomplete = |
| + new AutocompleteEditViewGtk(controller, |
| + toolbar_model, |
| + profile, |
| + command_updater, |
| + popup_window_mode, |
| + location_bar); |
| + autocomplete->Init(); |
| + |
| + // Make all the children of the widget visible. NOTE: this won't display |
| + // anything, it just toggles the visible flag. |
| + gtk_widget_show_all(autocomplete->GetNativeView()); |
| + // Hide the widget. NativeViewHostGtk will make it visible again as |
| + // necessary. |
| + gtk_widget_hide(autocomplete->GetNativeView()); |
| + |
| + autocomplete->CreateAccessibleWidgetHelper(IDS_ACCNAME_LOCATION); |
|
dmazzoni
2011/01/06 15:03:03
Why should this be a separate step? Could it be do
oshima
2011/01/06 19:43:35
Above functions are not called in gtk impl. I can
|
| + |
| + return autocomplete; |
| +} |
| +#endif |
| + |
| + |
| void AutocompleteEditViewGtk::Observe(NotificationType type, |
| const NotificationSource& source, |
| const NotificationDetails& details) { |