| 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 "views/controls/text_field.h" | 5 #include "views/controls/text_field.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlapp.h> | 8 #include <atlapp.h> |
| 9 #include <atlcrack.h> | 9 #include <atlcrack.h> |
| 10 #include <atlctrls.h> | 10 #include <atlctrls.h> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 void SetEnabled(bool enabled); | 65 void SetEnabled(bool enabled); |
| 66 | 66 |
| 67 void SetBackgroundColor(COLORREF bg_color); | 67 void SetBackgroundColor(COLORREF bg_color); |
| 68 | 68 |
| 69 // CWindowImpl | 69 // CWindowImpl |
| 70 BEGIN_MSG_MAP(Edit) | 70 BEGIN_MSG_MAP(Edit) |
| 71 MSG_WM_CHAR(OnChar) | 71 MSG_WM_CHAR(OnChar) |
| 72 MSG_WM_CONTEXTMENU(OnContextMenu) | 72 MSG_WM_CONTEXTMENU(OnContextMenu) |
| 73 MSG_WM_COPY(OnCopy) | 73 MSG_WM_COPY(OnCopy) |
| 74 MSG_WM_CREATE(OnCreate) | |
| 75 MSG_WM_CUT(OnCut) | 74 MSG_WM_CUT(OnCut) |
| 76 MSG_WM_DESTROY(OnDestroy) | |
| 77 MESSAGE_HANDLER_EX(WM_IME_CHAR, OnImeChar) | 75 MESSAGE_HANDLER_EX(WM_IME_CHAR, OnImeChar) |
| 78 MESSAGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, OnImeStartComposition) | 76 MESSAGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, OnImeStartComposition) |
| 79 MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeComposition) | 77 MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeComposition) |
| 80 MSG_WM_KEYDOWN(OnKeyDown) | 78 MSG_WM_KEYDOWN(OnKeyDown) |
| 81 MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) | 79 MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) |
| 82 MSG_WM_LBUTTONDOWN(OnLButtonDown) | 80 MSG_WM_LBUTTONDOWN(OnLButtonDown) |
| 83 MSG_WM_LBUTTONUP(OnLButtonUp) | 81 MSG_WM_LBUTTONUP(OnLButtonUp) |
| 84 MSG_WM_MBUTTONDOWN(OnNonLButtonDown) | 82 MSG_WM_MBUTTONDOWN(OnNonLButtonDown) |
| 85 MSG_WM_MOUSEMOVE(OnMouseMove) | 83 MSG_WM_MOUSEMOVE(OnMouseMove) |
| 86 MSG_WM_MOUSELEAVE(OnMouseLeave) | 84 MSG_WM_MOUSELEAVE(OnMouseLeave) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 114 Edit* const edit_; | 112 Edit* const edit_; |
| 115 ITextDocument* const text_object_model_; | 113 ITextDocument* const text_object_model_; |
| 116 | 114 |
| 117 DISALLOW_COPY_AND_ASSIGN(ScopedFreeze); | 115 DISALLOW_COPY_AND_ASSIGN(ScopedFreeze); |
| 118 }; | 116 }; |
| 119 | 117 |
| 120 // message handlers | 118 // message handlers |
| 121 void OnChar(TCHAR key, UINT repeat_count, UINT flags); | 119 void OnChar(TCHAR key, UINT repeat_count, UINT flags); |
| 122 void OnContextMenu(HWND window, const CPoint& point); | 120 void OnContextMenu(HWND window, const CPoint& point); |
| 123 void OnCopy(); | 121 void OnCopy(); |
| 124 LRESULT OnCreate(CREATESTRUCT* create_struct); | |
| 125 void OnCut(); | 122 void OnCut(); |
| 126 void OnDestroy(); | |
| 127 LRESULT OnImeChar(UINT message, WPARAM wparam, LPARAM lparam); | 123 LRESULT OnImeChar(UINT message, WPARAM wparam, LPARAM lparam); |
| 128 LRESULT OnImeStartComposition(UINT message, WPARAM wparam, LPARAM lparam); | 124 LRESULT OnImeStartComposition(UINT message, WPARAM wparam, LPARAM lparam); |
| 129 LRESULT OnImeComposition(UINT message, WPARAM wparam, LPARAM lparam); | 125 LRESULT OnImeComposition(UINT message, WPARAM wparam, LPARAM lparam); |
| 130 void OnKeyDown(TCHAR key, UINT repeat_count, UINT flags); | 126 void OnKeyDown(TCHAR key, UINT repeat_count, UINT flags); |
| 131 void OnLButtonDblClk(UINT keys, const CPoint& point); | 127 void OnLButtonDblClk(UINT keys, const CPoint& point); |
| 132 void OnLButtonDown(UINT keys, const CPoint& point); | 128 void OnLButtonDown(UINT keys, const CPoint& point); |
| 133 void OnLButtonUp(UINT keys, const CPoint& point); | 129 void OnLButtonUp(UINT keys, const CPoint& point); |
| 134 void OnMouseLeave(); | 130 void OnMouseLeave(); |
| 135 LRESULT OnMouseWheel(UINT message, WPARAM w_param, LPARAM l_param); | 131 LRESULT OnMouseWheel(UINT message, WPARAM w_param, LPARAM l_param); |
| 136 void OnMouseMove(UINT keys, const CPoint& point); | 132 void OnMouseMove(UINT keys, const CPoint& point); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 return; | 416 return; |
| 421 | 417 |
| 422 const std::wstring text(GetSelectedText()); | 418 const std::wstring text(GetSelectedText()); |
| 423 | 419 |
| 424 if (!text.empty() && ViewsDelegate::views_delegate) { | 420 if (!text.empty() && ViewsDelegate::views_delegate) { |
| 425 ScopedClipboardWriter scw(ViewsDelegate::views_delegate->GetClipboard()); | 421 ScopedClipboardWriter scw(ViewsDelegate::views_delegate->GetClipboard()); |
| 426 scw.WriteText(text); | 422 scw.WriteText(text); |
| 427 } | 423 } |
| 428 } | 424 } |
| 429 | 425 |
| 430 LRESULT TextField::Edit::OnCreate(CREATESTRUCT* create_struct) { | |
| 431 SetMsgHandled(FALSE); | |
| 432 TRACK_HWND_CREATION(m_hWnd); | |
| 433 return 0; | |
| 434 } | |
| 435 | |
| 436 void TextField::Edit::OnCut() { | 426 void TextField::Edit::OnCut() { |
| 437 if (parent_->IsReadOnly() || parent_->IsPassword()) | 427 if (parent_->IsReadOnly() || parent_->IsPassword()) |
| 438 return; | 428 return; |
| 439 | 429 |
| 440 OnCopy(); | 430 OnCopy(); |
| 441 | 431 |
| 442 // This replace selection will have no effect (even on the undo stack) if the | 432 // This replace selection will have no effect (even on the undo stack) if the |
| 443 // current selection is empty. | 433 // current selection is empty. |
| 444 ReplaceSel(L"", true); | 434 ReplaceSel(L"", true); |
| 445 } | 435 } |
| 446 | 436 |
| 447 void TextField::Edit::OnDestroy() { | |
| 448 TRACK_HWND_DESTRUCTION(m_hWnd); | |
| 449 } | |
| 450 | |
| 451 LRESULT TextField::Edit::OnImeChar(UINT message, WPARAM wparam, LPARAM lparam) { | 437 LRESULT TextField::Edit::OnImeChar(UINT message, WPARAM wparam, LPARAM lparam) { |
| 452 // http://crbug.com/7707: a rich-edit control may crash when it receives a | 438 // http://crbug.com/7707: a rich-edit control may crash when it receives a |
| 453 // WM_IME_CHAR message while it is processing a WM_IME_COMPOSITION message. | 439 // WM_IME_CHAR message while it is processing a WM_IME_COMPOSITION message. |
| 454 // Since view controls don't need WM_IME_CHAR messages, we prevent WM_IME_CHAR | 440 // Since view controls don't need WM_IME_CHAR messages, we prevent WM_IME_CHAR |
| 455 // messages from being dispatched to view controls via the CallWindowProc() | 441 // messages from being dispatched to view controls via the CallWindowProc() |
| 456 // call. | 442 // call. |
| 457 return 0; | 443 return 0; |
| 458 } | 444 } |
| 459 | 445 |
| 460 LRESULT TextField::Edit::OnImeStartComposition(UINT message, | 446 LRESULT TextField::Edit::OnImeStartComposition(UINT message, |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 | 1171 |
| 1186 COLORREF bg_color; | 1172 COLORREF bg_color; |
| 1187 if (!use_default_background_color_) | 1173 if (!use_default_background_color_) |
| 1188 bg_color = skia::SkColorToCOLORREF(background_color_); | 1174 bg_color = skia::SkColorToCOLORREF(background_color_); |
| 1189 else | 1175 else |
| 1190 bg_color = GetSysColor(read_only_ ? COLOR_3DFACE : COLOR_WINDOW); | 1176 bg_color = GetSysColor(read_only_ ? COLOR_3DFACE : COLOR_WINDOW); |
| 1191 edit_->SetBackgroundColor(bg_color); | 1177 edit_->SetBackgroundColor(bg_color); |
| 1192 } | 1178 } |
| 1193 | 1179 |
| 1194 } // namespace views | 1180 } // namespace views |
| OLD | NEW |