Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 10 matching lines...) Expand all Loading... | |
| 21 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
| 22 #include "ui/base/accessibility/accessible_view_state.h" | 22 #include "ui/base/accessibility/accessible_view_state.h" |
| 23 #include "ui/base/dragdrop/drag_drop_types.h" | 23 #include "ui/base/dragdrop/drag_drop_types.h" |
| 24 #include "ui/base/ime/text_input_type.h" | 24 #include "ui/base/ime/text_input_type.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/gfx/font.h" | 27 #include "ui/gfx/font.h" |
| 28 #include "ui/gfx/render_text.h" | 28 #include "ui/gfx/render_text.h" |
| 29 #include "views/border.h" | 29 #include "views/border.h" |
| 30 #include "views/controls/textfield/textfield.h" | 30 #include "views/controls/textfield/textfield.h" |
| 31 #include "views/events/event.h" | |
| 31 #include "views/layout/fill_layout.h" | 32 #include "views/layout/fill_layout.h" |
| 32 | 33 |
| 33 #if defined(TOUCH_UI) | 34 #if defined(TOUCH_UI) |
| 34 #include "chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents _view.h" | 35 #include "chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents _view.h" |
| 35 #else | 36 #else |
| 36 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h" | 37 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view. h" |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 39 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 40 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" | 41 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE { | 73 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE { |
| 73 return omnibox_view_->HandleKeyReleaseEvent(event); | 74 return omnibox_view_->HandleKeyReleaseEvent(event); |
| 74 } | 75 } |
| 75 | 76 |
| 76 virtual bool IsFocusable() const OVERRIDE { | 77 virtual bool IsFocusable() const OVERRIDE { |
| 77 // Bypass Textfield::IsFocusable. The omnibox in popup window requires | 78 // Bypass Textfield::IsFocusable. The omnibox in popup window requires |
| 78 // focus in order for text selection to work. | 79 // focus in order for text selection to work. |
| 79 return views::View::IsFocusable(); | 80 return views::View::IsFocusable(); |
| 80 } | 81 } |
| 81 | 82 |
| 83 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { | |
| 84 return omnibox_view_->HandleMousePressEvent(event); | |
| 85 } | |
| 86 | |
| 82 private: | 87 private: |
| 83 OmniboxViewViews* omnibox_view_; | 88 OmniboxViewViews* omnibox_view_; |
| 84 | 89 |
| 85 DISALLOW_COPY_AND_ASSIGN(AutocompleteTextfield); | 90 DISALLOW_COPY_AND_ASSIGN(AutocompleteTextfield); |
| 86 }; | 91 }; |
| 87 | 92 |
| 88 // Stores omnibox state for each tab. | 93 // Stores omnibox state for each tab. |
| 89 struct ViewState { | 94 struct ViewState { |
| 90 explicit ViewState(const gfx::SelectionModel& selection_model) | 95 explicit ViewState(const gfx::SelectionModel& selection_model) |
| 91 : selection_model(selection_model) { | 96 : selection_model(selection_model) { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 // the control-key state is changed. | 264 // the control-key state is changed. |
| 260 if (event.key_code() == ui::VKEY_CONTROL) { | 265 if (event.key_code() == ui::VKEY_CONTROL) { |
| 261 // TODO(oshima): investigate if we need to support keyboard with two | 266 // TODO(oshima): investigate if we need to support keyboard with two |
| 262 // controls. See omnibox_view_gtk.cc. | 267 // controls. See omnibox_view_gtk.cc. |
| 263 model_->OnControlKeyChanged(false); | 268 model_->OnControlKeyChanged(false); |
| 264 return true; | 269 return true; |
| 265 } | 270 } |
| 266 return false; | 271 return false; |
| 267 } | 272 } |
| 268 | 273 |
| 274 bool OmniboxViewViews::HandleMousePressEvent(const views::MouseEvent& event) { | |
| 275 if (event.IsOnlyLeftMouseButton() && !textfield_->HasFocus() && | |
|
msw
2011/11/11 01:28:58
We might want to do this for right mouse too. On W
jennyz
2011/11/12 01:50:17
Done.
| |
| 276 !textfield_->HasSelection()) { | |
| 277 textfield_->SelectAll(); | |
| 278 textfield_->RequestFocus(); | |
| 279 return true; | |
| 280 } | |
| 281 | |
| 282 return false; | |
| 283 } | |
| 284 | |
| 269 void OmniboxViewViews::HandleFocusIn() { | 285 void OmniboxViewViews::HandleFocusIn() { |
| 270 // TODO(oshima): Get control key state. | 286 // TODO(oshima): Get control key state. |
| 271 model_->OnSetFocus(false); | 287 model_->OnSetFocus(false); |
| 272 // Don't call controller_->OnSetFocus as this view has already | 288 // Don't call controller_->OnSetFocus as this view has already |
| 273 // acquired the focus. | 289 // acquired the focus. |
| 274 } | 290 } |
| 275 | 291 |
| 276 void OmniboxViewViews::HandleFocusOut() { | 292 void OmniboxViewViews::HandleFocusOut() { |
| 277 // TODO(oshima): we don't have native view. This requires | 293 // TODO(oshima): we don't have native view. This requires |
| 278 // further refactoring. | 294 // further refactoring. |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, | 747 OmniboxViewViews* omnibox_view = new OmniboxViewViews(controller, |
| 732 toolbar_model, | 748 toolbar_model, |
| 733 profile, | 749 profile, |
| 734 command_updater, | 750 command_updater, |
| 735 popup_window_mode, | 751 popup_window_mode, |
| 736 location_bar); | 752 location_bar); |
| 737 omnibox_view->Init(); | 753 omnibox_view->Init(); |
| 738 return omnibox_view; | 754 return omnibox_view; |
| 739 } | 755 } |
| 740 #endif | 756 #endif |
| OLD | NEW |