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..acf0fe4c978a40977b2846730090f39314492352 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,102 @@ CommandUpdater* AutocompleteEditViewGtk::GetCommandUpdater() { |
return command_updater_; |
} |
+#if defined(TOOLKIT_VIEWS) |
+views::View* AutocompleteEditViewGtk::AddToView(views::View* parent) { |
+ 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(); |
+} |
+ |
+void AutocompleteEditViewGtk::EnableAccessibility() { |
+ accessible_widget_helper_.reset( |
+ new AccessibleWidgetHelper(text_view(), model_->profile())); |
+ accessible_widget_helper_->SetWidgetName( |
+ text_view(), l10n_util::GetStringUTF8(IDS_ACCNAME_LOCATION)); |
+} |
+ |
+void AutocompleteEditViewGtk::SetInstantSuggestion(const string16& suggestion) { |
+ SetInstantSuggestion(UTF16ToUTF8(suggestion)); |
+} |
+#endif |
+ |
+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) |
+// 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->EnableAccessibility(); |
+ |
+ return autocomplete; |
+} |
+#endif |
+ |
void AutocompleteEditViewGtk::Observe(NotificationType type, |
const NotificationSource& source, |
const NotificationDetails& details) { |