OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 } | 743 } |
744 | 744 |
745 IAccessible* AutocompleteEditViewWin::GetIAccessible() { | 745 IAccessible* AutocompleteEditViewWin::GetIAccessible() { |
746 if (!autocomplete_accessibility_) { | 746 if (!autocomplete_accessibility_) { |
747 CComObject<AutocompleteAccessibility>* accessibility = NULL; | 747 CComObject<AutocompleteAccessibility>* accessibility = NULL; |
748 if (!SUCCEEDED(CComObject<AutocompleteAccessibility>::CreateInstance( | 748 if (!SUCCEEDED(CComObject<AutocompleteAccessibility>::CreateInstance( |
749 &accessibility)) || !accessibility) | 749 &accessibility)) || !accessibility) |
750 return NULL; | 750 return NULL; |
751 | 751 |
752 // Wrap the created object in a smart pointer so it won't leak. | 752 // Wrap the created object in a smart pointer so it won't leak. |
753 ScopedComPtr<IAccessible> accessibility_comptr(accessibility); | 753 base::win::ScopedComPtr<IAccessible> accessibility_comptr(accessibility); |
754 if (!SUCCEEDED(accessibility->Initialize(this))) | 754 if (!SUCCEEDED(accessibility->Initialize(this))) |
755 return NULL; | 755 return NULL; |
756 | 756 |
757 // Copy to the class smart pointer, and notify that an instance of | 757 // Copy to the class smart pointer, and notify that an instance of |
758 // IAccessible was allocated for m_hWnd. | 758 // IAccessible was allocated for m_hWnd. |
759 autocomplete_accessibility_ = accessibility_comptr; | 759 autocomplete_accessibility_ = accessibility_comptr; |
760 NotifyWinEvent(EVENT_OBJECT_CREATE, m_hWnd, OBJID_CLIENT, CHILDID_SELF); | 760 NotifyWinEvent(EVENT_OBJECT_CREATE, m_hWnd, OBJID_CLIENT, CHILDID_SELF); |
761 } | 761 } |
762 // Detach to leave ref counting to the caller. | 762 // Detach to leave ref counting to the caller. |
763 return autocomplete_accessibility_.Detach(); | 763 return autocomplete_accessibility_.Detach(); |
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2068 } | 2068 } |
2069 } | 2069 } |
2070 | 2070 |
2071 void AutocompleteEditViewWin::GetSelection(CHARRANGE& sel) const { | 2071 void AutocompleteEditViewWin::GetSelection(CHARRANGE& sel) const { |
2072 GetSel(sel); | 2072 GetSel(sel); |
2073 | 2073 |
2074 // See if we need to reverse the direction of the selection. | 2074 // See if we need to reverse the direction of the selection. |
2075 ITextDocument* const text_object_model = GetTextObjectModel(); | 2075 ITextDocument* const text_object_model = GetTextObjectModel(); |
2076 if (!text_object_model) | 2076 if (!text_object_model) |
2077 return; | 2077 return; |
2078 ScopedComPtr<ITextSelection> selection; | 2078 base::win::ScopedComPtr<ITextSelection> selection; |
2079 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); | 2079 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); |
2080 DCHECK_EQ(S_OK, hr); | 2080 DCHECK_EQ(S_OK, hr); |
2081 long flags; | 2081 long flags; |
2082 selection->GetFlags(&flags); | 2082 selection->GetFlags(&flags); |
2083 if (flags & tomSelStartActive) | 2083 if (flags & tomSelStartActive) |
2084 std::swap(sel.cpMin, sel.cpMax); | 2084 std::swap(sel.cpMin, sel.cpMax); |
2085 } | 2085 } |
2086 | 2086 |
2087 string16 AutocompleteEditViewWin::GetSelectedText() const { | 2087 string16 AutocompleteEditViewWin::GetSelectedText() const { |
2088 // Figure out the length of the selection. | 2088 // Figure out the length of the selection. |
2089 CHARRANGE sel; | 2089 CHARRANGE sel; |
2090 GetSel(sel); | 2090 GetSel(sel); |
2091 | 2091 |
2092 // Grab the selected text. | 2092 // Grab the selected text. |
2093 string16 str; | 2093 string16 str; |
2094 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); | 2094 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); |
2095 return str; | 2095 return str; |
2096 } | 2096 } |
2097 | 2097 |
2098 void AutocompleteEditViewWin::SetSelection(LONG start, LONG end) { | 2098 void AutocompleteEditViewWin::SetSelection(LONG start, LONG end) { |
2099 SetSel(start, end); | 2099 SetSel(start, end); |
2100 | 2100 |
2101 if (start <= end) | 2101 if (start <= end) |
2102 return; | 2102 return; |
2103 | 2103 |
2104 // We need to reverse the direction of the selection. | 2104 // We need to reverse the direction of the selection. |
2105 ITextDocument* const text_object_model = GetTextObjectModel(); | 2105 ITextDocument* const text_object_model = GetTextObjectModel(); |
2106 if (!text_object_model) | 2106 if (!text_object_model) |
2107 return; | 2107 return; |
2108 ScopedComPtr<ITextSelection> selection; | 2108 base::win::ScopedComPtr<ITextSelection> selection; |
2109 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); | 2109 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); |
2110 DCHECK_EQ(S_OK, hr); | 2110 DCHECK_EQ(S_OK, hr); |
2111 selection->SetFlags(tomSelStartActive); | 2111 selection->SetFlags(tomSelStartActive); |
2112 } | 2112 } |
2113 | 2113 |
2114 void AutocompleteEditViewWin::PlaceCaretAt(string16::size_type pos) { | 2114 void AutocompleteEditViewWin::PlaceCaretAt(string16::size_type pos) { |
2115 SetSelection(static_cast<LONG>(pos), static_cast<LONG>(pos)); | 2115 SetSelection(static_cast<LONG>(pos), static_cast<LONG>(pos)); |
2116 } | 2116 } |
2117 | 2117 |
2118 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const { | 2118 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2409 } | 2409 } |
2410 | 2410 |
2411 bool AutocompleteEditViewWin::CanPasteAndGo(const string16& text) const { | 2411 bool AutocompleteEditViewWin::CanPasteAndGo(const string16& text) const { |
2412 return !popup_window_mode_ && model_->CanPasteAndGo(text); | 2412 return !popup_window_mode_ && model_->CanPasteAndGo(text); |
2413 } | 2413 } |
2414 | 2414 |
2415 ITextDocument* AutocompleteEditViewWin::GetTextObjectModel() const { | 2415 ITextDocument* AutocompleteEditViewWin::GetTextObjectModel() const { |
2416 if (!text_object_model_) { | 2416 if (!text_object_model_) { |
2417 // This is lazily initialized, instead of being initialized in the | 2417 // This is lazily initialized, instead of being initialized in the |
2418 // constructor, in order to avoid hurting startup performance. | 2418 // constructor, in order to avoid hurting startup performance. |
2419 ScopedComPtr<IRichEditOle, NULL> ole_interface; | 2419 base::win::ScopedComPtr<IRichEditOle, NULL> ole_interface; |
2420 ole_interface.Attach(GetOleInterface()); | 2420 ole_interface.Attach(GetOleInterface()); |
2421 if (ole_interface) { | 2421 if (ole_interface) { |
2422 ole_interface.QueryInterface( | 2422 ole_interface.QueryInterface( |
2423 __uuidof(ITextDocument), | 2423 __uuidof(ITextDocument), |
2424 reinterpret_cast<void**>(&text_object_model_)); | 2424 reinterpret_cast<void**>(&text_object_model_)); |
2425 } | 2425 } |
2426 } | 2426 } |
2427 return text_object_model_; | 2427 return text_object_model_; |
2428 } | 2428 } |
2429 | 2429 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2620 // PosFromChar(i) might return 0 when i is greater than 1. | 2620 // PosFromChar(i) might return 0 when i is greater than 1. |
2621 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2621 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2622 } | 2622 } |
2623 | 2623 |
2624 bool AutocompleteEditViewWin::IsCaretAtEnd() const { | 2624 bool AutocompleteEditViewWin::IsCaretAtEnd() const { |
2625 long length = GetTextLength(); | 2625 long length = GetTextLength(); |
2626 CHARRANGE sel; | 2626 CHARRANGE sel; |
2627 GetSelection(sel); | 2627 GetSelection(sel); |
2628 return sel.cpMin == sel.cpMax && sel.cpMin == length; | 2628 return sel.cpMin == sel.cpMax && sel.cpMin == length; |
2629 } | 2629 } |
OLD | NEW |