Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc

Issue 10831407: Kill PropertyBag, switch WebContents to SupportsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/gtk/omnibox/omnibox_view_gtk.h" 5 #include "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/property_bag.h"
14 #include "base/string_util.h" 13 #include "base/string_util.h"
15 #include "base/utf_string_conversion_utils.h" 14 #include "base/utf_string_conversion_utils.h"
16 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
17 #include "chrome/app/chrome_command_ids.h" 16 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/autocomplete/autocomplete_input.h" 17 #include "chrome/browser/autocomplete/autocomplete_input.h"
19 #include "chrome/browser/autocomplete/autocomplete_match.h" 18 #include "chrome/browser/autocomplete/autocomplete_match.h"
20 #include "chrome/browser/bookmarks/bookmark_node_data.h" 19 #include "chrome/browser/bookmarks/bookmark_node_data.h"
21 #include "chrome/browser/command_updater.h" 20 #include "chrome/browser/command_updater.h"
22 #include "chrome/browser/defaults.h" 21 #include "chrome/browser/defaults.h"
23 #include "chrome/browser/instant/instant_controller.h" 22 #include "chrome/browser/instant/instant_controller.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Stores GTK+-specific state so it can be restored after switching tabs. 81 // Stores GTK+-specific state so it can be restored after switching tabs.
83 struct ViewState { 82 struct ViewState {
84 explicit ViewState(const OmniboxViewGtk::CharRange& selection_range) 83 explicit ViewState(const OmniboxViewGtk::CharRange& selection_range)
85 : selection_range(selection_range) { 84 : selection_range(selection_range) {
86 } 85 }
87 86
88 // Range of selected text. 87 // Range of selected text.
89 OmniboxViewGtk::CharRange selection_range; 88 OmniboxViewGtk::CharRange selection_range;
90 }; 89 };
91 90
92 struct AutocompleteEditState { 91 const char kAutocompleteEditStateKey[] = "AutocompleteEditState";
92
93 struct AutocompleteEditState : public base::SupportsUserData::Data {
93 AutocompleteEditState(const OmniboxEditModel::State& model_state, 94 AutocompleteEditState(const OmniboxEditModel::State& model_state,
94 const ViewState& view_state) 95 const ViewState& view_state)
95 : model_state(model_state), 96 : model_state(model_state),
96 view_state(view_state) { 97 view_state(view_state) {
97 } 98 }
99 virtual ~AutocompleteEditState() {}
98 100
99 const OmniboxEditModel::State model_state; 101 const OmniboxEditModel::State model_state;
100 const ViewState view_state; 102 const ViewState view_state;
101 }; 103 };
102 104
103 // Returns a lazily initialized property bag accessor for saving our state in a
104 // WebContents.
105 base::PropertyAccessor<AutocompleteEditState>* GetStateAccessor() {
106 CR_DEFINE_STATIC_LOCAL(
107 base::PropertyAccessor<AutocompleteEditState>, state, ());
108 return &state;
109 }
110
111 // Set up style properties to override the default GtkTextView; if a theme has 105 // Set up style properties to override the default GtkTextView; if a theme has
112 // overridden some of these properties, an inner-line will be displayed inside 106 // overridden some of these properties, an inner-line will be displayed inside
113 // the fake GtkTextEntry. 107 // the fake GtkTextEntry.
114 void SetEntryStyle() { 108 void SetEntryStyle() {
115 static bool style_was_set = false; 109 static bool style_was_set = false;
116 110
117 if (style_was_set) 111 if (style_was_set)
118 return; 112 return;
119 style_was_set = true; 113 style_was_set = true;
120 114
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 414 }
421 415
422 void OmniboxViewGtk::SaveStateToTab(WebContents* tab) { 416 void OmniboxViewGtk::SaveStateToTab(WebContents* tab) {
423 DCHECK(tab); 417 DCHECK(tab);
424 // If any text has been selected, register it as the PRIMARY selection so it 418 // If any text has been selected, register it as the PRIMARY selection so it
425 // can still be pasted via middle-click after the text view is cleared. 419 // can still be pasted via middle-click after the text view is cleared.
426 if (!selected_text_.empty()) 420 if (!selected_text_.empty())
427 SavePrimarySelection(selected_text_); 421 SavePrimarySelection(selected_text_);
428 // NOTE: GetStateForTabSwitch may affect GetSelection, so order is important. 422 // NOTE: GetStateForTabSwitch may affect GetSelection, so order is important.
429 OmniboxEditModel::State model_state = model()->GetStateForTabSwitch(); 423 OmniboxEditModel::State model_state = model()->GetStateForTabSwitch();
430 GetStateAccessor()->SetProperty( 424 tab->SetUserData(
431 tab->GetPropertyBag(), 425 kAutocompleteEditStateKey,
432 AutocompleteEditState(model_state, ViewState(GetSelection()))); 426 new AutocompleteEditState(model_state, ViewState(GetSelection())));
433 } 427 }
434 428
435 void OmniboxViewGtk::Update(const WebContents* contents) { 429 void OmniboxViewGtk::Update(const WebContents* contents) {
436 // NOTE: We're getting the URL text here from the ToolbarModel. 430 // NOTE: We're getting the URL text here from the ToolbarModel.
437 bool visibly_changed_permanent_text = 431 bool visibly_changed_permanent_text =
438 model()->UpdatePermanentText(toolbar_model()->GetText()); 432 model()->UpdatePermanentText(toolbar_model()->GetText());
439 433
440 ToolbarModel::SecurityLevel security_level = 434 ToolbarModel::SecurityLevel security_level =
441 toolbar_model()->GetSecurityLevel(); 435 toolbar_model()->GetSecurityLevel();
442 bool changed_security_level = (security_level != security_level_); 436 bool changed_security_level = (security_level != security_level_);
443 security_level_ = security_level; 437 security_level_ = security_level;
444 438
445 if (contents) { 439 if (contents) {
446 selected_text_.clear(); 440 selected_text_.clear();
447 RevertAll(); 441 RevertAll();
448 const AutocompleteEditState* state = 442 const AutocompleteEditState* state = static_cast<AutocompleteEditState*>(
449 GetStateAccessor()->GetProperty(contents->GetPropertyBag()); 443 contents->GetUserData(&kAutocompleteEditStateKey));
450 if (state) { 444 if (state) {
451 model()->RestoreState(state->model_state); 445 model()->RestoreState(state->model_state);
452 446
453 // Move the marks for the cursor and the other end of the selection to 447 // Move the marks for the cursor and the other end of the selection to
454 // the previously-saved offsets (but preserve PRIMARY). 448 // the previously-saved offsets (but preserve PRIMARY).
455 StartUpdatingHighlightedText(); 449 StartUpdatingHighlightedText();
456 SetSelectedRange(state->view_state.selection_range); 450 SetSelectedRange(state->view_state.selection_range);
457 FinishUpdatingHighlightedText(); 451 FinishUpdatingHighlightedText();
458 } 452 }
459 } else if (visibly_changed_permanent_text) { 453 } else if (visibly_changed_permanent_text) {
(...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 void OmniboxViewGtk::AdjustVerticalAlignmentOfInstantView() { 2168 void OmniboxViewGtk::AdjustVerticalAlignmentOfInstantView() {
2175 // By default, GtkTextView layouts an anchored child widget just above the 2169 // By default, GtkTextView layouts an anchored child widget just above the
2176 // baseline, so we need to move the |instant_view_| down to make sure it 2170 // baseline, so we need to move the |instant_view_| down to make sure it
2177 // has the same baseline as the |text_view_|. 2171 // has the same baseline as the |text_view_|.
2178 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_)); 2172 PangoLayout* layout = gtk_label_get_layout(GTK_LABEL(instant_view_));
2179 int height; 2173 int height;
2180 pango_layout_get_size(layout, NULL, &height); 2174 pango_layout_get_size(layout, NULL, &height);
2181 int baseline = pango_layout_get_baseline(layout); 2175 int baseline = pango_layout_get_baseline(layout);
2182 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL); 2176 g_object_set(instant_anchor_tag_, "rise", baseline - height, NULL);
2183 } 2177 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/web_dialog_window_controller.mm ('k') | chrome/browser/ui/gtk/web_dialog_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698