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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_win.cc

Issue 4637002: Adds the ability for classes other than native control to process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome
Patch Set: Tweaks Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/autocomplete/autocomplete_edit_view_win.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <locale> 8 #include <locale>
9 #include <string> 9 #include <string>
10 10
11 #include <richedit.h> 11 #include <richedit.h>
12 #include <textserv.h> 12 #include <textserv.h>
13 13
14 #include "app/clipboard/clipboard.h" 14 #include "app/clipboard/clipboard.h"
15 #include "app/clipboard/scoped_clipboard_writer.h" 15 #include "app/clipboard/scoped_clipboard_writer.h"
16 #include "app/keyboard_codes.h" 16 #include "app/keyboard_codes.h"
17 #include "app/l10n_util.h" 17 #include "app/l10n_util.h"
18 #include "app/l10n_util_win.h" 18 #include "app/l10n_util_win.h"
19 #include "app/os_exchange_data.h" 19 #include "app/os_exchange_data.h"
20 #include "app/os_exchange_data_provider_win.h" 20 #include "app/os_exchange_data_provider_win.h"
21 #include "app/win_util.h" 21 #include "app/win_util.h"
22 #include "app/win/drag_source.h" 22 #include "app/win/drag_source.h"
23 #include "app/win/drop_target.h" 23 #include "app/win/drop_target.h"
24 #include "app/win/iat_patch_function.h" 24 #include "app/win/iat_patch_function.h"
25 #include "app/win/scoped_prop.h"
25 #include "base/auto_reset.h" 26 #include "base/auto_reset.h"
26 #include "base/basictypes.h" 27 #include "base/basictypes.h"
27 #include "base/i18n/rtl.h" 28 #include "base/i18n/rtl.h"
28 #include "base/lazy_instance.h" 29 #include "base/lazy_instance.h"
29 #include "base/ref_counted.h" 30 #include "base/ref_counted.h"
30 #include "base/string_util.h" 31 #include "base/string_util.h"
31 #include "base/utf_string_conversions.h" 32 #include "base/utf_string_conversions.h"
32 #include "chrome/app/chrome_command_ids.h" 33 #include "chrome/app/chrome_command_ids.h"
33 #include "chrome/browser/autocomplete/autocomplete_accessibility.h" 34 #include "chrome/browser/autocomplete/autocomplete_accessibility.h"
34 #include "chrome/browser/autocomplete/autocomplete_match.h" 35 #include "chrome/browser/autocomplete/autocomplete_match.h"
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 432
432 Create(hwnd, 0, 0, 0, l10n_util::GetExtendedStyles()); 433 Create(hwnd, 0, 0, 0, l10n_util::GetExtendedStyles());
433 SetReadOnly(popup_window_mode_); 434 SetReadOnly(popup_window_mode_);
434 SetFont(font_.GetNativeFont()); 435 SetFont(font_.GetNativeFont());
435 436
436 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as 437 // NOTE: Do not use SetWordBreakProcEx() here, that is no longer supported as
437 // of Rich Edit 2.0 onward. 438 // of Rich Edit 2.0 onward.
438 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, 439 SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0,
439 reinterpret_cast<LPARAM>(&WordBreakProc)); 440 reinterpret_cast<LPARAM>(&WordBreakProc));
440 441
442 // Makes it EN_SELCHANGE is sent to our parent window and back to us by way of
443 // ProcessWindowMessage.
444 SetEventMask(ENM_SELCHANGE);
445
441 // Get the metrics for the font. 446 // Get the metrics for the font.
442 HDC dc = ::GetDC(NULL); 447 HDC dc = ::GetDC(NULL);
443 SelectObject(dc, font_.GetNativeFont()); 448 SelectObject(dc, font_.GetNativeFont());
444 TEXTMETRIC tm = {0}; 449 TEXTMETRIC tm = {0};
445 GetTextMetrics(dc, &tm); 450 GetTextMetrics(dc, &tm);
446 const float kXHeightRatio = 0.7f; // The ratio of a font's x-height to its 451 const float kXHeightRatio = 0.7f; // The ratio of a font's x-height to its
447 // cap height. Sadly, Windows doesn't 452 // cap height. Sadly, Windows doesn't
448 // provide a true value for a font's 453 // provide a true value for a font's
449 // x-height in its text metrics, so we 454 // x-height in its text metrics, so we
450 // approximate. 455 // approximate.
(...skipping 10 matching lines...) Expand all
461 ::ReleaseDC(NULL, dc); 466 ::ReleaseDC(NULL, dc);
462 467
463 // Set the default character style -- adjust to our desired baseline. 468 // Set the default character style -- adjust to our desired baseline.
464 CHARFORMAT cf = {0}; 469 CHARFORMAT cf = {0};
465 cf.dwMask = CFM_OFFSET; 470 cf.dwMask = CFM_OFFSET;
466 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel; 471 cf.yOffset = -font_y_adjustment_ * kTwipsPerPixel;
467 SetDefaultCharFormat(cf); 472 SetDefaultCharFormat(cf);
468 473
469 SetBackgroundColor(background_color_); 474 SetBackgroundColor(background_color_);
470 475
476 message_handler_prop_.reset(
477 views::ChildWindowMessageProcessor::Register(m_hWnd, this));
478
471 // By default RichEdit has a drop target. Revoke it so that we can install our 479 // By default RichEdit has a drop target. Revoke it so that we can install our
472 // own. Revoke takes care of deleting the existing one. 480 // own. Revoke takes care of deleting the existing one.
473 RevokeDragDrop(m_hWnd); 481 RevokeDragDrop(m_hWnd);
474 482
475 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when 483 // Register our drop target. RichEdit appears to invoke RevokeDropTarget when
476 // done so that we don't have to explicitly. 484 // done so that we don't have to explicitly.
477 if (!popup_window_mode_) { 485 if (!popup_window_mode_) {
478 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this); 486 scoped_refptr<EditDropTarget> drop_target = new EditDropTarget(this);
479 RegisterDragDrop(m_hWnd, drop_target.get()); 487 RegisterDragDrop(m_hWnd, drop_target.get());
480 } 488 }
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); 1057 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES);
1050 break; 1058 break;
1051 1059
1052 default: 1060 default:
1053 NOTREACHED(); 1061 NOTREACHED();
1054 break; 1062 break;
1055 } 1063 }
1056 OnAfterPossibleChange(); 1064 OnAfterPossibleChange();
1057 } 1065 }
1058 1066
1067 bool AutocompleteEditViewWin::ProcessMessage(UINT message,
1068 WPARAM w_param,
1069 LPARAM l_param,
1070 LRESULT* result) {
1071 if (message == WM_NOTIFY) {
1072 NMHDR* header = reinterpret_cast<NMHDR*>(l_param);
1073 if (header->code == EN_SELCHANGE) {
1074 // TODO(sky): wire this up.
1075 }
1076 }
1077 return false;
1078 }
1079
1059 // static 1080 // static
1060 int CALLBACK AutocompleteEditViewWin::WordBreakProc(LPTSTR edit_text, 1081 int CALLBACK AutocompleteEditViewWin::WordBreakProc(LPTSTR edit_text,
1061 int current_pos, 1082 int current_pos,
1062 int num_bytes, 1083 int num_bytes,
1063 int action) { 1084 int action) {
1064 // TODO(pkasting): http://b/1111308 We should let other people, like ICU and 1085 // TODO(pkasting): http://b/1111308 We should let other people, like ICU and
1065 // GURL, do the work for us here instead of writing all this ourselves. 1086 // GURL, do the work for us here instead of writing all this ourselves.
1066 1087
1067 // Sadly, even though the MSDN docs claim that the third parameter here is a 1088 // Sadly, even though the MSDN docs claim that the third parameter here is a
1068 // number of characters, they lie. It's a number of bytes. 1089 // number of characters, they lie. It's a number of bytes.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 } 1260 }
1240 1261
1241 void AutocompleteEditViewWin::OnCut() { 1262 void AutocompleteEditViewWin::OnCut() {
1242 OnCopy(); 1263 OnCopy();
1243 1264
1244 // This replace selection will have no effect (even on the undo stack) if the 1265 // This replace selection will have no effect (even on the undo stack) if the
1245 // current selection is empty. 1266 // current selection is empty.
1246 ReplaceSel(L"", true); 1267 ReplaceSel(L"", true);
1247 } 1268 }
1248 1269
1270 void AutocompleteEditViewWin::OnDestroy() {
1271 message_handler_prop_.reset();
1272 }
1273
1249 LRESULT AutocompleteEditViewWin::OnGetObject(UINT uMsg, 1274 LRESULT AutocompleteEditViewWin::OnGetObject(UINT uMsg,
1250 WPARAM wparam, 1275 WPARAM wparam,
1251 LPARAM lparam) { 1276 LPARAM lparam) {
1252 // Accessibility readers will send an OBJID_CLIENT message. 1277 // Accessibility readers will send an OBJID_CLIENT message.
1253 if (lparam == OBJID_CLIENT) { 1278 if (lparam == OBJID_CLIENT) {
1254 // Re-attach for internal re-usage of accessibility pointer. 1279 // Re-attach for internal re-usage of accessibility pointer.
1255 autocomplete_accessibility_.Attach(GetIAccessible()); 1280 autocomplete_accessibility_.Attach(GetIAccessible());
1256 1281
1257 if (autocomplete_accessibility_) { 1282 if (autocomplete_accessibility_) {
1258 return LresultFromObject(IID_IAccessible, wparam, 1283 return LresultFromObject(IID_IAccessible, wparam,
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 return (rect.left - client_rect.left) + (client_rect.right - rect.right); 2587 return (rect.left - client_rect.left) + (client_rect.right - rect.right);
2563 } 2588 }
2564 2589
2565 int AutocompleteEditViewWin::WidthNeededToDisplay(const std::wstring& text) { 2590 int AutocompleteEditViewWin::WidthNeededToDisplay(const std::wstring& text) {
2566 // Use font_.GetStringWidth() instead of 2591 // Use font_.GetStringWidth() instead of
2567 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is 2592 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
2568 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, 2593 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout,
2569 // PosFromChar(i) might return 0 when i is greater than 1. 2594 // PosFromChar(i) might return 0 when i is greater than 1.
2570 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2595 return font_.GetStringWidth(text) + GetHorizontalMargin();
2571 } 2596 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_win.h ('k') | views/controls/native_control_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698