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/ui/views/omnibox/omnibox_view_win.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 // synchronously change the permanent text to the new URL. If we don't freeze | 637 // synchronously change the permanent text to the new URL. If we don't freeze |
638 // here, the user could potentially see a flicker of the current URL before | 638 // here, the user could potentially see a flicker of the current URL before |
639 // the new one reappears, which would look glitchy. | 639 // the new one reappears, which would look glitchy. |
640 ScopedFreeze freeze(this, GetTextObjectModel()); | 640 ScopedFreeze freeze(this, GetTextObjectModel()); |
641 model_->OpenMatch(match, disposition, alternate_nav_url, | 641 model_->OpenMatch(match, disposition, alternate_nav_url, |
642 selected_line, keyword); | 642 selected_line, keyword); |
643 } | 643 } |
644 | 644 |
645 string16 OmniboxViewWin::GetText() const { | 645 string16 OmniboxViewWin::GetText() const { |
646 const int len = GetTextLength() + 1; | 646 const int len = GetTextLength() + 1; |
647 if (len <= 1) | |
648 return string16(); | |
649 | |
650 string16 str; | 647 string16 str; |
651 GetWindowText(WriteInto(&str, len), len); | 648 if (len > 1) |
| 649 GetWindowText(WriteInto(&str, len), len); |
652 return str; | 650 return str; |
653 } | 651 } |
654 | 652 |
655 bool OmniboxViewWin::IsEditingOrEmpty() const { | 653 bool OmniboxViewWin::IsEditingOrEmpty() const { |
656 return model_->user_input_in_progress() || (GetTextLength() == 0); | 654 return model_->user_input_in_progress() || (GetTextLength() == 0); |
657 } | 655 } |
658 | 656 |
659 int OmniboxViewWin::GetIcon() const { | 657 int OmniboxViewWin::GetIcon() const { |
660 return IsEditingOrEmpty() ? | 658 return IsEditingOrEmpty() ? |
661 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : | 659 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : |
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 base::win::ScopedComPtr<ITextSelection> selection; | 2109 base::win::ScopedComPtr<ITextSelection> selection; |
2112 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); | 2110 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); |
2113 DCHECK_EQ(S_OK, hr); | 2111 DCHECK_EQ(S_OK, hr); |
2114 long flags; | 2112 long flags; |
2115 selection->GetFlags(&flags); | 2113 selection->GetFlags(&flags); |
2116 if (flags & tomSelStartActive) | 2114 if (flags & tomSelStartActive) |
2117 std::swap(sel.cpMin, sel.cpMax); | 2115 std::swap(sel.cpMin, sel.cpMax); |
2118 } | 2116 } |
2119 | 2117 |
2120 string16 OmniboxViewWin::GetSelectedText() const { | 2118 string16 OmniboxViewWin::GetSelectedText() const { |
2121 // Figure out the length of the selection. | |
2122 CHARRANGE sel; | 2119 CHARRANGE sel; |
2123 GetSel(sel); | 2120 GetSel(sel); |
2124 if (sel.cpMin == sel.cpMax) // GetSelText() crashes on NULL input. | |
2125 return string16(); | |
2126 | |
2127 // Grab the selected text. | |
2128 string16 str; | 2121 string16 str; |
2129 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); | 2122 if (sel.cpMin != sel.cpMax) |
| 2123 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); |
2130 return str; | 2124 return str; |
2131 } | 2125 } |
2132 | 2126 |
2133 void OmniboxViewWin::SetSelection(LONG start, LONG end) { | 2127 void OmniboxViewWin::SetSelection(LONG start, LONG end) { |
2134 SetSel(start, end); | 2128 SetSel(start, end); |
2135 | 2129 |
2136 if (start <= end) | 2130 if (start <= end) |
2137 return; | 2131 return; |
2138 | 2132 |
2139 // We need to reverse the direction of the selection. | 2133 // We need to reverse the direction of the selection. |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2652 // PosFromChar(i) might return 0 when i is greater than 1. | 2646 // PosFromChar(i) might return 0 when i is greater than 1. |
2653 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2647 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2654 } | 2648 } |
2655 | 2649 |
2656 bool OmniboxViewWin::IsCaretAtEnd() const { | 2650 bool OmniboxViewWin::IsCaretAtEnd() const { |
2657 long length = GetTextLength(); | 2651 long length = GetTextLength(); |
2658 CHARRANGE sel; | 2652 CHARRANGE sel; |
2659 GetSelection(sel); | 2653 GetSelection(sel); |
2660 return sel.cpMin == sel.cpMax && sel.cpMin == length; | 2654 return sel.cpMin == sel.cpMax && sel.cpMin == length; |
2661 } | 2655 } |
OLD | NEW |