| 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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
| 6 #include "app/l10n_util_win.h" | 6 #include "app/l10n_util_win.h" |
| 7 #include "app/win_util.h" | 7 #include "app/win_util.h" |
| 8 #include "base/clipboard.h" | 8 #include "base/clipboard.h" |
| 9 #include "base/gfx/native_theme.h" | 9 #include "base/gfx/native_theme.h" |
| 10 #include "base/scoped_clipboard_writer.h" | 10 #include "base/scoped_clipboard_writer.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (textfield_->style() & Textfield::STYLE_LOWERCASE) { | 90 if (textfield_->style() & Textfield::STYLE_LOWERCASE) { |
| 91 DCHECK((textfield_->style() & Textfield::STYLE_PASSWORD) == 0); | 91 DCHECK((textfield_->style() & Textfield::STYLE_PASSWORD) == 0); |
| 92 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); | 92 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Set up the text_object_model_. | 95 // Set up the text_object_model_. |
| 96 CComPtr<IRichEditOle> ole_interface; | 96 CComPtr<IRichEditOle> ole_interface; |
| 97 ole_interface.Attach(GetOleInterface()); | 97 ole_interface.Attach(GetOleInterface()); |
| 98 text_object_model_ = ole_interface; | 98 text_object_model_ = ole_interface; |
| 99 | 99 |
| 100 context_menu_.reset(new MenuWin(this, Menu::TOPLEFT, m_hWnd)); | |
| 101 context_menu_->AppendMenuItemWithLabel(IDS_APP_UNDO, | |
| 102 l10n_util::GetString(IDS_APP_UNDO)); | |
| 103 context_menu_->AppendSeparator(); | |
| 104 context_menu_->AppendMenuItemWithLabel(IDS_APP_CUT, | |
| 105 l10n_util::GetString(IDS_APP_CUT)); | |
| 106 context_menu_->AppendMenuItemWithLabel(IDS_APP_COPY, | |
| 107 l10n_util::GetString(IDS_APP_COPY)); | |
| 108 context_menu_->AppendMenuItemWithLabel(IDS_APP_PASTE, | |
| 109 l10n_util::GetString(IDS_APP_PASTE)); | |
| 110 context_menu_->AppendSeparator(); | |
| 111 context_menu_->AppendMenuItemWithLabel( | |
| 112 IDS_APP_SELECT_ALL, | |
| 113 l10n_util::GetString(IDS_APP_SELECT_ALL)); | |
| 114 | |
| 115 container_view_ = new NativeViewHost; | 100 container_view_ = new NativeViewHost; |
| 116 textfield_->AddChildView(container_view_); | 101 textfield_->AddChildView(container_view_); |
| 117 container_view_->set_focus_view(textfield_); | 102 container_view_->set_focus_view(textfield_); |
| 118 container_view_->Attach(m_hWnd); | 103 container_view_->Attach(m_hWnd); |
| 119 } | 104 } |
| 120 | 105 |
| 121 NativeTextfieldWin::~NativeTextfieldWin() { | 106 NativeTextfieldWin::~NativeTextfieldWin() { |
| 122 if (IsWindow()) | 107 if (IsWindow()) |
| 123 DestroyWindow(); | 108 DestroyWindow(); |
| 124 } | 109 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 205 |
| 221 View* NativeTextfieldWin::GetView() { | 206 View* NativeTextfieldWin::GetView() { |
| 222 return container_view_; | 207 return container_view_; |
| 223 } | 208 } |
| 224 | 209 |
| 225 gfx::NativeView NativeTextfieldWin::GetTestingHandle() const { | 210 gfx::NativeView NativeTextfieldWin::GetTestingHandle() const { |
| 226 return m_hWnd; | 211 return m_hWnd; |
| 227 } | 212 } |
| 228 | 213 |
| 229 //////////////////////////////////////////////////////////////////////////////// | 214 //////////////////////////////////////////////////////////////////////////////// |
| 230 // NativeTextfieldWin, Menu::Delegate implementation: | 215 // NativeTextfieldWin, SimpleMenuModel::Delegate implementation: |
| 231 | 216 |
| 232 bool NativeTextfieldWin::IsCommandEnabled(int id) const { | 217 bool NativeTextfieldWin::IsCommandIdChecked(int command_id) const { |
| 233 switch (id) { | 218 return false; |
| 219 } |
| 220 |
| 221 bool NativeTextfieldWin::IsCommandIdEnabled(int command_id) const { |
| 222 switch (command_id) { |
| 234 case IDS_APP_UNDO: return !textfield_->read_only() && !!CanUndo(); | 223 case IDS_APP_UNDO: return !textfield_->read_only() && !!CanUndo(); |
| 235 case IDS_APP_CUT: return !textfield_->read_only() && | 224 case IDS_APP_CUT: return !textfield_->read_only() && |
| 236 !textfield_->IsPassword() && !!CanCut(); | 225 !textfield_->IsPassword() && !!CanCut(); |
| 237 case IDS_APP_COPY: return !!CanCopy() && !textfield_->IsPassword(); | 226 case IDS_APP_COPY: return !!CanCopy() && !textfield_->IsPassword(); |
| 238 case IDS_APP_PASTE: return !textfield_->read_only() && !!CanPaste(); | 227 case IDS_APP_PASTE: return !textfield_->read_only() && !!CanPaste(); |
| 239 case IDS_APP_SELECT_ALL: return !!CanSelectAll(); | 228 case IDS_APP_SELECT_ALL: return !!CanSelectAll(); |
| 240 default: NOTREACHED(); | 229 default: NOTREACHED(); |
| 241 return false; | 230 return false; |
| 242 } | 231 } |
| 243 } | 232 } |
| 244 | 233 |
| 245 void NativeTextfieldWin::ExecuteCommand(int id) { | 234 bool NativeTextfieldWin::GetAcceleratorForCommandId(int command_id, |
| 235 Accelerator* accelerator) { |
| 236 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators |
| 237 // anywhere so we need to check for them explicitly here. |
| 238 switch (command_id) { |
| 239 case IDS_APP_CUT: |
| 240 *accelerator = views::Accelerator(L'X', false, true, false); |
| 241 return true; |
| 242 case IDS_APP_COPY: |
| 243 *accelerator = views::Accelerator(L'C', false, true, false); |
| 244 return true; |
| 245 case IDS_APP_PASTE: |
| 246 *accelerator = views::Accelerator(L'V', false, true, false); |
| 247 return true; |
| 248 } |
| 249 return container_view_->GetWidget()->GetAccelerator(command_id, accelerator); |
| 250 } |
| 251 |
| 252 void NativeTextfieldWin::ExecuteCommand(int command_id) { |
| 246 ScopedFreeze freeze(this, GetTextObjectModel()); | 253 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 247 OnBeforePossibleChange(); | 254 OnBeforePossibleChange(); |
| 248 switch (id) { | 255 switch (command_id) { |
| 249 case IDS_APP_UNDO: Undo(); break; | 256 case IDS_APP_UNDO: Undo(); break; |
| 250 case IDS_APP_CUT: Cut(); break; | 257 case IDS_APP_CUT: Cut(); break; |
| 251 case IDS_APP_COPY: Copy(); break; | 258 case IDS_APP_COPY: Copy(); break; |
| 252 case IDS_APP_PASTE: Paste(); break; | 259 case IDS_APP_PASTE: Paste(); break; |
| 253 case IDS_APP_SELECT_ALL: SelectAll(); break; | 260 case IDS_APP_SELECT_ALL: SelectAll(); break; |
| 254 default: NOTREACHED(); break; | 261 default: NOTREACHED(); break; |
| 255 } | 262 } |
| 256 OnAfterPossibleChange(); | 263 OnAfterPossibleChange(); |
| 257 } | 264 } |
| 258 | 265 |
| 259 //////////////////////////////////////////////////////////////////////////////// | 266 //////////////////////////////////////////////////////////////////////////////// |
| 260 // NativeTextfieldWin, private: | 267 // NativeTextfieldWin, private: |
| 261 | 268 |
| 262 void NativeTextfieldWin::OnChar(TCHAR ch, UINT repeat_count, UINT flags) { | 269 void NativeTextfieldWin::OnChar(TCHAR ch, UINT repeat_count, UINT flags) { |
| 263 HandleKeystroke(GetCurrentMessage()->message, ch, repeat_count, flags); | 270 HandleKeystroke(GetCurrentMessage()->message, ch, repeat_count, flags); |
| 264 } | 271 } |
| 265 | 272 |
| 266 void NativeTextfieldWin::OnContextMenu(HWND window, const CPoint& point) { | 273 void NativeTextfieldWin::OnContextMenu(HWND window, const CPoint& point) { |
| 267 CPoint p(point); | 274 CPoint p(point); |
| 268 if (point.x == -1 || point.y == -1) { | 275 if (point.x == -1 || point.y == -1) { |
| 269 GetCaretPos(&p); | 276 GetCaretPos(&p); |
| 270 MapWindowPoints(HWND_DESKTOP, &p, 1); | 277 MapWindowPoints(HWND_DESKTOP, &p, 1); |
| 271 } | 278 } |
| 272 context_menu_->RunMenuAt(p.x, p.y); | 279 BuildContextMenu(); |
| 280 context_menu_->RunContextMenuAt(gfx::Point(p)); |
| 273 } | 281 } |
| 274 | 282 |
| 275 void NativeTextfieldWin::OnCopy() { | 283 void NativeTextfieldWin::OnCopy() { |
| 276 if (textfield_->IsPassword()) | 284 if (textfield_->IsPassword()) |
| 277 return; | 285 return; |
| 278 | 286 |
| 279 const std::wstring text(GetSelectedText()); | 287 const std::wstring text(GetSelectedText()); |
| 280 | 288 |
| 281 if (!text.empty() && ViewsDelegate::views_delegate) { | 289 if (!text.empty() && ViewsDelegate::views_delegate) { |
| 282 ScopedClipboardWriter scw(ViewsDelegate::views_delegate->GetClipboard()); | 290 ScopedClipboardWriter scw(ViewsDelegate::views_delegate->GetClipboard()); |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 | 838 |
| 831 ITextDocument* NativeTextfieldWin::GetTextObjectModel() const { | 839 ITextDocument* NativeTextfieldWin::GetTextObjectModel() const { |
| 832 if (!text_object_model_) { | 840 if (!text_object_model_) { |
| 833 CComPtr<IRichEditOle> ole_interface; | 841 CComPtr<IRichEditOle> ole_interface; |
| 834 ole_interface.Attach(GetOleInterface()); | 842 ole_interface.Attach(GetOleInterface()); |
| 835 text_object_model_ = ole_interface; | 843 text_object_model_ = ole_interface; |
| 836 } | 844 } |
| 837 return text_object_model_; | 845 return text_object_model_; |
| 838 } | 846 } |
| 839 | 847 |
| 848 void NativeTextfieldWin::BuildContextMenu() { |
| 849 if (context_menu_contents_.get()) |
| 850 return; |
| 851 context_menu_contents_.reset(new SimpleMenuModel(this)); |
| 852 context_menu_contents_->AddItemWithStringId(IDS_APP_UNDO, IDS_APP_UNDO); |
| 853 context_menu_contents_->AddSeparator(); |
| 854 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); |
| 855 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 856 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); |
| 857 context_menu_contents_->AddSeparator(); |
| 858 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 859 IDS_APP_SELECT_ALL); |
| 860 context_menu_.reset(new Menu2(context_menu_contents_.get())); |
| 861 } |
| 862 |
| 840 //////////////////////////////////////////////////////////////////////////////// | 863 //////////////////////////////////////////////////////////////////////////////// |
| 841 // NativeTextfieldWrapper, public: | 864 // NativeTextfieldWrapper, public: |
| 842 | 865 |
| 843 // static | 866 // static |
| 844 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 867 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 845 Textfield* field) { | 868 Textfield* field) { |
| 846 return new NativeTextfieldWin(field); | 869 return new NativeTextfieldWin(field); |
| 847 } | 870 } |
| 848 | 871 |
| 849 } // namespace views | 872 } // namespace views |
| OLD | NEW |