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

Side by Side Diff: views/controls/textfield/native_textfield_win.cc

Issue 200045: Use Scoped[Bstr,ComPtr,Variant] instead of their ATL equivalents to reduce de... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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) 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 <algorithm>
6
5 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
6 #include "app/l10n_util_win.h" 8 #include "app/l10n_util_win.h"
7 #include "app/win_util.h" 9 #include "app/win_util.h"
8 #include "base/clipboard.h" 10 #include "base/clipboard.h"
9 #include "base/gfx/native_theme.h" 11 #include "base/gfx/native_theme.h"
10 #include "base/scoped_clipboard_writer.h" 12 #include "base/scoped_clipboard_writer.h"
11 #include "base/string_util.h" 13 #include "base/string_util.h"
12 #include "base/win_util.h" 14 #include "base/win_util.h"
13 #include "grit/app_strings.h" 15 #include "grit/app_strings.h"
14 #include "skia/ext/skia_utils_win.h" 16 #include "skia/ext/skia_utils_win.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 89
88 RECT r = {0, 0, textfield_->width(), textfield_->height()}; 90 RECT r = {0, 0, textfield_->width(), textfield_->height()};
89 Create(textfield_->GetWidget()->GetNativeView(), r, NULL, style, ex_style); 91 Create(textfield_->GetWidget()->GetNativeView(), r, NULL, style, ex_style);
90 92
91 if (textfield_->style() & Textfield::STYLE_LOWERCASE) { 93 if (textfield_->style() & Textfield::STYLE_LOWERCASE) {
92 DCHECK((textfield_->style() & Textfield::STYLE_PASSWORD) == 0); 94 DCHECK((textfield_->style() & Textfield::STYLE_PASSWORD) == 0);
93 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE); 95 SetEditStyle(SES_LOWERCASE, SES_LOWERCASE);
94 } 96 }
95 97
96 // Set up the text_object_model_. 98 // Set up the text_object_model_.
97 CComPtr<IRichEditOle> ole_interface; 99 ScopedComPtr<IRichEditOle, &IID_IRichEditOle> ole_interface;
98 ole_interface.Attach(GetOleInterface()); 100 ole_interface.Attach(GetOleInterface());
99 text_object_model_ = ole_interface; 101 text_object_model_.QueryFrom(ole_interface);
100 } 102 }
101 103
102 NativeTextfieldWin::~NativeTextfieldWin() { 104 NativeTextfieldWin::~NativeTextfieldWin() {
103 if (IsWindow()) 105 if (IsWindow())
104 DestroyWindow(); 106 DestroyWindow();
105 } 107 }
106 108
107 void NativeTextfieldWin::AttachHack() { 109 void NativeTextfieldWin::AttachHack() {
108 // See the code in textfield.cc that calls this for why this is here. 110 // See the code in textfield.cc that calls this for why this is here.
109 container_view_->set_focus_view(textfield_); 111 container_view_->set_focus_view(textfield_);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 if (textfield_->read_only() || textfield_->IsPassword()) 300 if (textfield_->read_only() || textfield_->IsPassword())
299 return; 301 return;
300 302
301 OnCopy(); 303 OnCopy();
302 304
303 // This replace selection will have no effect (even on the undo stack) if the 305 // This replace selection will have no effect (even on the undo stack) if the
304 // current selection is empty. 306 // current selection is empty.
305 ReplaceSel(L"", true); 307 ReplaceSel(L"", true);
306 } 308 }
307 309
308 LRESULT NativeTextfieldWin::OnImeChar(UINT message, WPARAM wparam, LPARAM lparam ) { 310 LRESULT NativeTextfieldWin::OnImeChar(UINT message,
311 WPARAM wparam,
312 LPARAM lparam) {
309 // http://crbug.com/7707: a rich-edit control may crash when it receives a 313 // http://crbug.com/7707: a rich-edit control may crash when it receives a
310 // WM_IME_CHAR message while it is processing a WM_IME_COMPOSITION message. 314 // WM_IME_CHAR message while it is processing a WM_IME_COMPOSITION message.
311 // Since view controls don't need WM_IME_CHAR messages, we prevent WM_IME_CHAR 315 // Since view controls don't need WM_IME_CHAR messages, we prevent WM_IME_CHAR
312 // messages from being dispatched to view controls via the CallWindowProc() 316 // messages from being dispatched to view controls via the CallWindowProc()
313 // call. 317 // call.
314 return 0; 318 return 0;
315 } 319 }
316 320
317 LRESULT NativeTextfieldWin::OnImeStartComposition(UINT message, 321 LRESULT NativeTextfieldWin::OnImeStartComposition(UINT message,
318 WPARAM wparam, 322 WPARAM wparam,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 void NativeTextfieldWin::OnMouseLeave() { 509 void NativeTextfieldWin::OnMouseLeave() {
506 SetContainsMouse(false); 510 SetContainsMouse(false);
507 } 511 }
508 512
509 LRESULT NativeTextfieldWin::OnMouseWheel(UINT message, WPARAM w_param, 513 LRESULT NativeTextfieldWin::OnMouseWheel(UINT message, WPARAM w_param,
510 LPARAM l_param) { 514 LPARAM l_param) {
511 // Reroute the mouse-wheel to the window under the mouse pointer if 515 // Reroute the mouse-wheel to the window under the mouse pointer if
512 // applicable. 516 // applicable.
513 if (views::RerouteMouseWheel(m_hWnd, w_param, l_param)) 517 if (views::RerouteMouseWheel(m_hWnd, w_param, l_param))
514 return 0; 518 return 0;
515 return DefWindowProc(message, w_param, l_param);; 519 return DefWindowProc(message, w_param, l_param);
516 } 520 }
517 521
518 void NativeTextfieldWin::OnMouseMove(UINT keys, const CPoint& point) { 522 void NativeTextfieldWin::OnMouseMove(UINT keys, const CPoint& point) {
519 SetContainsMouse(true); 523 SetContainsMouse(true);
520 // Clamp the selection to the visible text so the user can't drag to select 524 // Clamp the selection to the visible text so the user can't drag to select
521 // the "phantom newline". In theory we could achieve this by clipping the X 525 // the "phantom newline". In theory we could achieve this by clipping the X
522 // coordinate, but in practice the edit seems to behave nondeterministically 526 // coordinate, but in practice the edit seems to behave nondeterministically
523 // with similar sequences of clipped input coordinates fed to it. Maybe it's 527 // with similar sequences of clipped input coordinates fed to it. Maybe it's
524 // reading the mouse cursor position directly? 528 // reading the mouse cursor position directly?
525 // 529 //
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 tme.dwFlags = TME_LEAVE; 839 tme.dwFlags = TME_LEAVE;
836 tme.hwndTrack = m_hWnd; 840 tme.hwndTrack = m_hWnd;
837 tme.dwHoverTime = 0; 841 tme.dwHoverTime = 0;
838 TrackMouseEvent(&tme); 842 TrackMouseEvent(&tme);
839 } 843 }
840 RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_FRAME); 844 RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_FRAME);
841 } 845 }
842 846
843 ITextDocument* NativeTextfieldWin::GetTextObjectModel() const { 847 ITextDocument* NativeTextfieldWin::GetTextObjectModel() const {
844 if (!text_object_model_) { 848 if (!text_object_model_) {
845 CComPtr<IRichEditOle> ole_interface; 849 ScopedComPtr<IRichEditOle, &IID_IRichEditOle> ole_interface;
846 ole_interface.Attach(GetOleInterface()); 850 ole_interface.Attach(GetOleInterface());
847 text_object_model_ = ole_interface; 851 text_object_model_.QueryFrom(ole_interface);
848 } 852 }
849 return text_object_model_; 853 return text_object_model_;
850 } 854 }
851 855
852 void NativeTextfieldWin::BuildContextMenu() { 856 void NativeTextfieldWin::BuildContextMenu() {
853 if (context_menu_contents_.get()) 857 if (context_menu_contents_.get())
854 return; 858 return;
855 context_menu_contents_.reset(new SimpleMenuModel(this)); 859 context_menu_contents_.reset(new SimpleMenuModel(this));
856 context_menu_contents_->AddItemWithStringId(IDS_APP_UNDO, IDS_APP_UNDO); 860 context_menu_contents_->AddItemWithStringId(IDS_APP_UNDO, IDS_APP_UNDO);
857 context_menu_contents_->AddSeparator(); 861 context_menu_contents_->AddSeparator();
858 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); 862 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT);
859 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); 863 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY);
860 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); 864 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE);
861 context_menu_contents_->AddSeparator(); 865 context_menu_contents_->AddSeparator();
862 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL, 866 context_menu_contents_->AddItemWithStringId(IDS_APP_SELECT_ALL,
863 IDS_APP_SELECT_ALL); 867 IDS_APP_SELECT_ALL);
864 context_menu_.reset(new Menu2(context_menu_contents_.get())); 868 context_menu_.reset(new Menu2(context_menu_contents_.get()));
865 } 869 }
866 870
867 //////////////////////////////////////////////////////////////////////////////// 871 ////////////////////////////////////////////////////////////////////////////////
868 // NativeTextfieldWrapper, public: 872 // NativeTextfieldWrapper, public:
869 873
870 // static 874 // static
871 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( 875 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper(
872 Textfield* field) { 876 Textfield* field) {
873 return new NativeTextfieldWin(field); 877 return new NativeTextfieldWin(field);
874 } 878 }
875 879
876 } // namespace views 880 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698