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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 12299002: Consolidate Omnibox ViewState and AutocompleteEditState, rename. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase Created 7 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/views/omnibox/omnibox_view_views.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 21 matching lines...) Expand all
32 #include "ui/base/dragdrop/drag_drop_types.h" 32 #include "ui/base/dragdrop/drag_drop_types.h"
33 #include "ui/base/dragdrop/os_exchange_data.h" 33 #include "ui/base/dragdrop/os_exchange_data.h"
34 #include "ui/base/events/event.h" 34 #include "ui/base/events/event.h"
35 #include "ui/base/ime/text_input_client.h" 35 #include "ui/base/ime/text_input_client.h"
36 #include "ui/base/ime/text_input_type.h" 36 #include "ui/base/ime/text_input_type.h"
37 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/models/simple_menu_model.h" 38 #include "ui/base/models/simple_menu_model.h"
39 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
40 #include "ui/gfx/canvas.h" 40 #include "ui/gfx/canvas.h"
41 #include "ui/gfx/font.h" 41 #include "ui/gfx/font.h"
42 #include "ui/gfx/render_text.h" 42 #include "ui/gfx/selection_model.h"
43 #include "ui/views/border.h" 43 #include "ui/views/border.h"
44 #include "ui/views/controls/textfield/textfield.h" 44 #include "ui/views/controls/textfield/textfield.h"
45 #include "ui/views/ime/input_method.h" 45 #include "ui/views/ime/input_method.h"
46 #include "ui/views/layout/fill_layout.h" 46 #include "ui/views/layout/fill_layout.h"
47 #include "ui/views/views_delegate.h" 47 #include "ui/views/views_delegate.h"
48 #include "ui/views/widget/widget.h" 48 #include "ui/views/widget/widget.h"
49 49
50 #if defined(USE_AURA) 50 #if defined(USE_AURA)
51 #include "ui/aura/focus_manager.h" 51 #include "ui/aura/focus_manager.h"
52 #include "ui/aura/root_window.h" 52 #include "ui/aura/root_window.h"
53 #include "ui/compositor/layer.h" 53 #include "ui/compositor/layer.h"
54 #endif 54 #endif
55 55
56 using content::WebContents;
57
58 namespace { 56 namespace {
59 57
60 // Stores omnibox state for each tab. 58 // Stores omnibox state for each tab.
61 struct ViewState { 59 struct OmniboxState : public base::SupportsUserData::Data {
62 explicit ViewState(const gfx::SelectionModel& selection_model) 60 static const char kKey[];
63 : selection_model(selection_model) {
64 }
65 61
66 // SelectionModel of selected text. 62 OmniboxState(const OmniboxEditModel::State& model_state,
67 gfx::SelectionModel selection_model; 63 const gfx::SelectionModel& selection_model);
64 virtual ~OmniboxState();
65
66 const OmniboxEditModel::State model_state;
67 const gfx::SelectionModel selection_model;
68 }; 68 };
69 69
70 const char kAutocompleteEditStateKey[] = "AutocompleteEditState"; 70 // static
71 const char OmniboxState::kKey[] = "OmniboxState";
71 72
72 struct AutocompleteEditState : public base::SupportsUserData::Data { 73 OmniboxState::OmniboxState(const OmniboxEditModel::State& model_state,
73 AutocompleteEditState(const OmniboxEditModel::State& model_state, 74 const gfx::SelectionModel& selection_model)
74 const ViewState& view_state) 75 : model_state(model_state),
75 : model_state(model_state), 76 selection_model(selection_model) {
76 view_state(view_state) { 77 }
77 }
78 virtual ~AutocompleteEditState() {}
79 78
80 const OmniboxEditModel::State model_state; 79 OmniboxState::~OmniboxState() {}
81 const ViewState view_state;
82 };
83 80
84 // The following const value is the same as in browser_defaults. 81 // The following const value is the same as in browser_defaults.
85 const int kAutocompleteEditFontPixelSize = 15; 82 const int kAutocompleteEditFontPixelSize = 15;
86 // Font size 10px (as defined in browser_defaults) is too small for many 83 // Font size 10px (as defined in browser_defaults) is too small for many
87 // non-Latin/Greek/Cyrillic (non-LGC) scripts. For pop-up window, the total 84 // non-Latin/Greek/Cyrillic (non-LGC) scripts. For pop-up window, the total
88 // rectangle is 21px tall and the height available for "ink" is 17px (please 85 // rectangle is 21px tall and the height available for "ink" is 17px (please
89 // refer to kAutocompleteVerticalMarginInPopup). With 12px font size, the 86 // refer to kAutocompleteVerticalMarginInPopup). With 12px font size, the
90 // tallest glyphs in UI fonts we're building for ChromeOS (across all scripts) 87 // tallest glyphs in UI fonts we're building for ChromeOS (across all scripts)
91 // still fit within 17px "ink" height. 88 // still fit within 17px "ink" height.
92 const int kAutocompleteEditFontPixelSizeInPopup = 12; 89 const int kAutocompleteEditFontPixelSizeInPopup = 12;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 // Close the popup. 352 // Close the popup.
356 CloseOmniboxPopup(); 353 CloseOmniboxPopup();
357 // Tell the model to reset itself. 354 // Tell the model to reset itself.
358 model()->OnKillFocus(); 355 model()->OnKillFocus();
359 controller()->OnKillFocus(); 356 controller()->OnKillFocus();
360 } 357 }
361 358
362 //////////////////////////////////////////////////////////////////////////////// 359 ////////////////////////////////////////////////////////////////////////////////
363 // OmniboxViewViews, OmniboxView implementation: 360 // OmniboxViewViews, OmniboxView implementation:
364 361
365 void OmniboxViewViews::SaveStateToTab(WebContents* tab) { 362 void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) {
366 DCHECK(tab); 363 DCHECK(tab);
367 364
368 // We don't want to keep the IME status, so force quit the current 365 // We don't want to keep the IME status, so force quit the current
369 // session here. It may affect the selection status, so order is 366 // session here. It may affect the selection status, so order is
370 // also important. 367 // also important.
371 if (IsIMEComposing()) { 368 if (IsIMEComposing()) {
372 GetTextInputClient()->ConfirmCompositionText(); 369 GetTextInputClient()->ConfirmCompositionText();
373 GetInputMethod()->CancelComposition(this); 370 GetInputMethod()->CancelComposition(this);
374 } 371 }
375 372
376 // NOTE: GetStateForTabSwitch may affect GetSelection, so order is important. 373 // NOTE: GetStateForTabSwitch may affect GetSelection, so order is important.
377 OmniboxEditModel::State model_state = model()->GetStateForTabSwitch(); 374 OmniboxEditModel::State state = model()->GetStateForTabSwitch();
378 gfx::SelectionModel selection; 375 gfx::SelectionModel selection;
379 GetSelectionModel(&selection); 376 GetSelectionModel(&selection);
380 tab->SetUserData( 377 tab->SetUserData(OmniboxState::kKey, new OmniboxState(state, selection));
381 kAutocompleteEditStateKey,
382 new AutocompleteEditState(model_state, ViewState(selection)));
383 } 378 }
384 379
385 void OmniboxViewViews::Update(const WebContents* contents) { 380 void OmniboxViewViews::Update(const content::WebContents* contents) {
386 // NOTE: We're getting the URL text here from the ToolbarModel. 381 // NOTE: We're getting the URL text here from the ToolbarModel.
387 bool visibly_changed_permanent_text = 382 bool visibly_changed_permanent_text =
388 model()->UpdatePermanentText(toolbar_model()->GetText(true)); 383 model()->UpdatePermanentText(toolbar_model()->GetText(true));
389 ToolbarModel::SecurityLevel security_level = 384 ToolbarModel::SecurityLevel security_level =
390 toolbar_model()->GetSecurityLevel(); 385 toolbar_model()->GetSecurityLevel();
391 bool changed_security_level = (security_level != security_level_); 386 bool changed_security_level = (security_level != security_level_);
392 security_level_ = security_level; 387 security_level_ = security_level;
393 388
394 // TODO(oshima): Copied from gtk implementation which is 389 // TODO(msw|oshima): Copied from GTK, determine correct Win/CrOS behavior.
395 // slightly different from WIN impl. Find out the correct implementation
396 // for views-implementation.
397 if (contents) { 390 if (contents) {
398 RevertAll(); 391 RevertAll();
399 const AutocompleteEditState* state = static_cast<AutocompleteEditState*>( 392 const OmniboxState* state = static_cast<OmniboxState*>(
400 contents->GetUserData(&kAutocompleteEditStateKey)); 393 contents->GetUserData(&OmniboxState::kKey));
401 if (state) { 394 if (state) {
395 // Restore the saved state and selection.
402 model()->RestoreState(state->model_state); 396 model()->RestoreState(state->model_state);
403 397 SelectSelectionModel(state->selection_model);
404 // Move the marks for the cursor and the other end of the selection to 398 // TODO(oshima): Consider saving/restoring edit history.
405 // the previously-saved offsets (but preserve PRIMARY).
406 SelectSelectionModel(state->view_state.selection_model);
407 // We do not carry over the current edit history to another tab.
408 // TODO(oshima): consider saving/restoring edit history.
409 ClearEditHistory(); 399 ClearEditHistory();
410 } 400 }
411 } else if (visibly_changed_permanent_text) { 401 } else if (visibly_changed_permanent_text) {
412 RevertAll(); 402 RevertAll();
413 } else if (changed_security_level) { 403 } else if (changed_security_level) {
414 EmphasizeURLComponents(); 404 EmphasizeURLComponents();
415 } 405 }
416 } 406 }
417 407
418 string16 OmniboxViewViews::GetText() const { 408 string16 OmniboxViewViews::GetText() const {
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 const string16 text(GetClipboardText()); 854 const string16 text(GetClipboardText());
865 if (!text.empty()) { 855 if (!text.empty()) {
866 // Record this paste, so we can do different behavior. 856 // Record this paste, so we can do different behavior.
867 model()->on_paste(); 857 model()->on_paste();
868 // Force a Paste operation to trigger the text_changed code in 858 // Force a Paste operation to trigger the text_changed code in
869 // OnAfterPossibleChange(), even if identical contents are pasted. 859 // OnAfterPossibleChange(), even if identical contents are pasted.
870 text_before_change_.clear(); 860 text_before_change_.clear();
871 ReplaceSelection(text); 861 ReplaceSelection(text);
872 } 862 }
873 } 863 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698