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

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

Issue 6036004: Refactor AutocompleteEditViewGtk so that AutocompleteEditView impl can be swapped. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 11 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) 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
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 // before we free the library. If the library gets unloaded before this 491 // before we free the library. If the library gets unloaded before this
492 // released, it becomes garbage. 492 // released, it becomes garbage.
493 text_object_model_->Release(); 493 text_object_model_->Release();
494 494
495 // We balance our reference count and unpatch when the last instance has 495 // We balance our reference count and unpatch when the last instance has
496 // been destroyed. This prevents us from relying on the AtExit or static 496 // been destroyed. This prevents us from relying on the AtExit or static
497 // destructor sequence to do our unpatching, which is generally fragile. 497 // destructor sequence to do our unpatching, which is generally fragile.
498 g_paint_patcher.Pointer()->DerefPatch(); 498 g_paint_patcher.Pointer()->DerefPatch();
499 } 499 }
500 500
501 int AutocompleteEditViewWin::TextWidth() {
502 return WidthNeededToDisplay(GetText());
503 }
504
505 int AutocompleteEditViewWin::WidthOfTextAfterCursor() { 501 int AutocompleteEditViewWin::WidthOfTextAfterCursor() {
506 CHARRANGE selection; 502 CHARRANGE selection;
507 GetSelection(selection); 503 GetSelection(selection);
508 const int start = std::max(0, static_cast<int>(selection.cpMax - 1)); 504 const int start = std::max(0, static_cast<int>(selection.cpMax - 1));
509 return WidthNeededToDisplay(GetText().substr(start)); 505 return WidthNeededToDisplay(GetText().substr(start));
510 } 506 }
511 507
512 gfx::Font AutocompleteEditViewWin::GetFont() { 508 gfx::Font AutocompleteEditViewWin::GetFont() {
513 return font_; 509 return font_;
514 } 510 }
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 } 902 }
907 903
908 gfx::NativeView AutocompleteEditViewWin::GetNativeView() const { 904 gfx::NativeView AutocompleteEditViewWin::GetNativeView() const {
909 return m_hWnd; 905 return m_hWnd;
910 } 906 }
911 907
912 CommandUpdater* AutocompleteEditViewWin::GetCommandUpdater() { 908 CommandUpdater* AutocompleteEditViewWin::GetCommandUpdater() {
913 return command_updater_; 909 return command_updater_;
914 } 910 }
915 911
912 views::View* AutocompleteEditViewWin::AddToView(views::View* parent) {
913 views::NativeViewHost* host = new views::NativeViewHost;
914 parent->AddChildView(host);
915 host->set_focus_view(parent);
916 host->Attach(GetNativeView());
917 return host;
918 }
919
920 bool AutocompleteEditViewWin::CommitInstantSuggestion(
921 const std::wstring& typed_text,
922 const std::wstring& suggested_text) {
923 model_->FinalizeInstantQuery(typed_text, suggested_text);
924 return true;
925 }
926
927 void AutocompleteEditViewWin::SetInstantSuggestion(const string16& suggestion) {
928 // Win shows the suggestion in LocationBarView.
929 NOTREACHED();
930 }
931
932 int AutocompleteEditViewWin::TextWidth() const {
933 return WidthNeededToDisplay(GetText());
934 }
935
916 void AutocompleteEditViewWin::PasteAndGo(const std::wstring& text) { 936 void AutocompleteEditViewWin::PasteAndGo(const std::wstring& text) {
917 if (CanPasteAndGo(text)) 937 if (CanPasteAndGo(text))
918 model_->PasteAndGo(); 938 model_->PasteAndGo();
919 } 939 }
920 940
921 bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing( 941 bool AutocompleteEditViewWin::SkipDefaultKeyEventProcessing(
922 const views::KeyEvent& e) { 942 const views::KeyEvent& e) {
923 app::KeyboardCode key = e.GetKeyCode(); 943 app::KeyboardCode key = e.GetKeyCode();
924 // We don't process ALT + numpad digit as accelerators, they are used for 944 // We don't process ALT + numpad digit as accelerators, they are used for
925 // entering special characters. We do translate alt-home. 945 // entering special characters. We do translate alt-home.
(...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after
2563 const CPoint& point) { 2583 const CPoint& point) {
2564 if (gaining_focus_.get()) { 2584 if (gaining_focus_.get()) {
2565 // This click is giving us focus, so we need to track how much the mouse 2585 // This click is giving us focus, so we need to track how much the mouse
2566 // moves to see if it's a drag or just a click. Clicks should select all 2586 // moves to see if it's a drag or just a click. Clicks should select all
2567 // the text. 2587 // the text.
2568 tracking_click_[button] = true; 2588 tracking_click_[button] = true;
2569 click_point_[button] = point; 2589 click_point_[button] = point;
2570 } 2590 }
2571 } 2591 }
2572 2592
2573 int AutocompleteEditViewWin::GetHorizontalMargin() { 2593 int AutocompleteEditViewWin::GetHorizontalMargin() const {
2574 RECT rect; 2594 RECT rect;
2575 GetRect(&rect); 2595 GetRect(&rect);
2576 RECT client_rect; 2596 RECT client_rect;
2577 GetClientRect(&client_rect); 2597 GetClientRect(&client_rect);
2578 return (rect.left - client_rect.left) + (client_rect.right - rect.right); 2598 return (rect.left - client_rect.left) + (client_rect.right - rect.right);
2579 } 2599 }
2580 2600
2581 int AutocompleteEditViewWin::WidthNeededToDisplay(const std::wstring& text) { 2601 int AutocompleteEditViewWin::WidthNeededToDisplay(
2602 const std::wstring& text) const {
2582 // Use font_.GetStringWidth() instead of 2603 // Use font_.GetStringWidth() instead of
2583 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is 2604 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is
2584 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, 2605 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout,
2585 // PosFromChar(i) might return 0 when i is greater than 1. 2606 // PosFromChar(i) might return 0 when i is greater than 1.
2586 return font_.GetStringWidth(text) + GetHorizontalMargin(); 2607 return font_.GetStringWidth(text) + GetHorizontalMargin();
2587 } 2608 }
2588 2609
2589 bool AutocompleteEditViewWin::IsImeComposing() const { 2610 bool AutocompleteEditViewWin::IsImeComposing() const {
2590 bool ime_composing = false; 2611 bool ime_composing = false;
2591 HIMC context = ImmGetContext(m_hWnd); 2612 HIMC context = ImmGetContext(m_hWnd);
2592 if (context) { 2613 if (context) {
2593 ime_composing = !!ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0); 2614 ime_composing = !!ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0);
2594 ImmReleaseContext(m_hWnd, context); 2615 ImmReleaseContext(m_hWnd, context);
2595 } 2616 }
2596 return ime_composing; 2617 return ime_composing;
2597 } 2618 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698