| 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_edit_view_gtk.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 return &state; | 63 return &state; |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace | 66 } // namespace |
| 67 | 67 |
| 68 AutocompleteEditViewGtk::AutocompleteEditViewGtk( | 68 AutocompleteEditViewGtk::AutocompleteEditViewGtk( |
| 69 AutocompleteEditController* controller, | 69 AutocompleteEditController* controller, |
| 70 ToolbarModel* toolbar_model, | 70 ToolbarModel* toolbar_model, |
| 71 Profile* profile, | 71 Profile* profile, |
| 72 CommandUpdater* command_updater, | 72 CommandUpdater* command_updater, |
| 73 bool popup_window_mode, |
| 73 AutocompletePopupPositioner* popup_positioner) | 74 AutocompletePopupPositioner* popup_positioner) |
| 74 : text_view_(NULL), | 75 : text_view_(NULL), |
| 75 tag_table_(NULL), | 76 tag_table_(NULL), |
| 76 text_buffer_(NULL), | 77 text_buffer_(NULL), |
| 77 base_tag_(NULL), | 78 base_tag_(NULL), |
| 78 secure_scheme_tag_(NULL), | 79 secure_scheme_tag_(NULL), |
| 79 insecure_scheme_tag_(NULL), | 80 insecure_scheme_tag_(NULL), |
| 80 model_(new AutocompleteEditModel(this, controller, profile)), | 81 model_(new AutocompleteEditModel(this, controller, profile)), |
| 81 popup_view_(new AutocompletePopupViewGtk(this, model_.get(), profile, | 82 popup_view_(new AutocompletePopupViewGtk(this, model_.get(), profile, |
| 82 popup_positioner)), | 83 popup_positioner)), |
| 83 controller_(controller), | 84 controller_(controller), |
| 84 toolbar_model_(toolbar_model), | 85 toolbar_model_(toolbar_model), |
| 85 command_updater_(command_updater), | 86 command_updater_(command_updater), |
| 86 popup_window_mode_(false), // TODO(deanm) | 87 popup_window_mode_(popup_window_mode), |
| 87 scheme_security_level_(ToolbarModel::NORMAL), | 88 scheme_security_level_(ToolbarModel::NORMAL), |
| 88 selection_saved_(false), | 89 selection_saved_(false), |
| 89 mark_set_handler_id_(0), | 90 mark_set_handler_id_(0), |
| 90 button_1_pressed_(false), | 91 button_1_pressed_(false), |
| 91 text_selected_during_click_(false), | 92 text_selected_during_click_(false), |
| 92 text_view_focused_before_button_press_(false) { | 93 text_view_focused_before_button_press_(false) { |
| 93 model_->set_popup_model(popup_view_->GetModel()); | 94 model_->set_popup_model(popup_view_->GetModel()); |
| 94 } | 95 } |
| 95 | 96 |
| 96 AutocompleteEditViewGtk::~AutocompleteEditViewGtk() { | 97 AutocompleteEditViewGtk::~AutocompleteEditViewGtk() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 118 // The height of the text view is going to change based on the font used. We | 119 // The height of the text view is going to change based on the font used. We |
| 119 // don't want to stretch the height, and we want it vertically centered. | 120 // don't want to stretch the height, and we want it vertically centered. |
| 120 alignment_.Own(gtk_alignment_new(0., 0.5, 1.0, 0.0)); | 121 alignment_.Own(gtk_alignment_new(0., 0.5, 1.0, 0.0)); |
| 121 | 122 |
| 122 // The GtkTagTable and GtkTextBuffer are not initially unowned, so we have | 123 // The GtkTagTable and GtkTextBuffer are not initially unowned, so we have |
| 123 // our own reference when we create them, and we own them. Adding them to | 124 // our own reference when we create them, and we own them. Adding them to |
| 124 // the other objects adds a reference; it doesn't adopt them. | 125 // the other objects adds a reference; it doesn't adopt them. |
| 125 tag_table_ = gtk_text_tag_table_new(); | 126 tag_table_ = gtk_text_tag_table_new(); |
| 126 text_buffer_ = gtk_text_buffer_new(tag_table_); | 127 text_buffer_ = gtk_text_buffer_new(tag_table_); |
| 127 text_view_ = gtk_text_view_new_with_buffer(text_buffer_); | 128 text_view_ = gtk_text_view_new_with_buffer(text_buffer_); |
| 129 if (popup_window_mode_) |
| 130 gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view_), false); |
| 128 if (browser_defaults::kForceAutocompleteEditFontSize) { | 131 if (browser_defaults::kForceAutocompleteEditFontSize) { |
| 129 // Until we switch to vector graphics, force the font size. | 132 // Until we switch to vector graphics, force the font size. |
| 130 gtk_util::ForceFontSizePixels(text_view_, 13.4); // 13.4px == 10pt @ 96dpi | 133 const double kFontSize = 13.4; // 13.4px == 10pt @ 96dpi |
| 134 // On Windows, popups have a font size 5/6 the size of non-popups. |
| 135 const double kPopupWindowFontSize = kFontSize * 5.0 / 6.0; |
| 136 gtk_util::ForceFontSizePixels(text_view_, |
| 137 popup_window_mode_ ? kPopupWindowFontSize : kFontSize); |
| 131 } | 138 } |
| 132 | 139 |
| 133 // Override the background color for now. http://crbug.com/12195 | 140 // Override the background color for now. http://crbug.com/12195 |
| 134 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, | 141 gtk_widget_modify_base(text_view_, GTK_STATE_NORMAL, |
| 135 &LocationBarViewGtk::kBackgroundColorByLevel[scheme_security_level_]); | 142 &LocationBarViewGtk::kBackgroundColorByLevel[scheme_security_level_]); |
| 136 | 143 |
| 137 // The text view was floating. It will now be owned by the alignment. | 144 // The text view was floating. It will now be owned by the alignment. |
| 138 gtk_container_add(GTK_CONTAINER(alignment_.get()), text_view_); | 145 gtk_container_add(GTK_CONTAINER(alignment_.get()), text_view_); |
| 139 | 146 |
| 140 // TODO(deanm): This will probably have to be handled differently with the | 147 // TODO(deanm): This will probably have to be handled differently with the |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 const std::string& selected_text) { | 803 const std::string& selected_text) { |
| 797 GtkClipboard* clipboard = | 804 GtkClipboard* clipboard = |
| 798 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); | 805 gtk_widget_get_clipboard(text_view_, GDK_SELECTION_PRIMARY); |
| 799 DCHECK(clipboard); | 806 DCHECK(clipboard); |
| 800 if (!clipboard) | 807 if (!clipboard) |
| 801 return; | 808 return; |
| 802 | 809 |
| 803 gtk_clipboard_set_text( | 810 gtk_clipboard_set_text( |
| 804 clipboard, selected_text.data(), selected_text.size()); | 811 clipboard, selected_text.data(), selected_text.size()); |
| 805 } | 812 } |
| OLD | NEW |