| 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 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 // synchronously change the permanent text to the new URL. If we don't freeze | 638 // synchronously change the permanent text to the new URL. If we don't freeze |
| 639 // here, the user could potentially see a flicker of the current URL before | 639 // here, the user could potentially see a flicker of the current URL before |
| 640 // the new one reappears, which would look glitchy. | 640 // the new one reappears, which would look glitchy. |
| 641 ScopedFreeze freeze(this, GetTextObjectModel()); | 641 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 642 model_->OpenMatch(match, disposition, alternate_nav_url, | 642 model_->OpenMatch(match, disposition, alternate_nav_url, |
| 643 selected_line, keyword); | 643 selected_line, keyword); |
| 644 } | 644 } |
| 645 | 645 |
| 646 string16 OmniboxViewWin::GetText() const { | 646 string16 OmniboxViewWin::GetText() const { |
| 647 const int len = GetTextLength() + 1; | 647 const int len = GetTextLength() + 1; |
| 648 if (len <= 1) | |
| 649 return string16(); | |
| 650 | |
| 651 string16 str; | 648 string16 str; |
| 652 GetWindowText(WriteInto(&str, len), len); | 649 if (len > 1) |
| 650 GetWindowText(WriteInto(&str, len), len); |
| 653 return str; | 651 return str; |
| 654 } | 652 } |
| 655 | 653 |
| 656 bool OmniboxViewWin::IsEditingOrEmpty() const { | 654 bool OmniboxViewWin::IsEditingOrEmpty() const { |
| 657 return model_->user_input_in_progress() || (GetTextLength() == 0); | 655 return model_->user_input_in_progress() || (GetTextLength() == 0); |
| 658 } | 656 } |
| 659 | 657 |
| 660 int OmniboxViewWin::GetIcon() const { | 658 int OmniboxViewWin::GetIcon() const { |
| 661 return IsEditingOrEmpty() ? | 659 return IsEditingOrEmpty() ? |
| 662 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : | 660 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : |
| (...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2121 base::win::ScopedComPtr<ITextSelection> selection; | 2119 base::win::ScopedComPtr<ITextSelection> selection; |
| 2122 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); | 2120 const HRESULT hr = text_object_model->GetSelection(selection.Receive()); |
| 2123 DCHECK_EQ(S_OK, hr); | 2121 DCHECK_EQ(S_OK, hr); |
| 2124 long flags; | 2122 long flags; |
| 2125 selection->GetFlags(&flags); | 2123 selection->GetFlags(&flags); |
| 2126 if (flags & tomSelStartActive) | 2124 if (flags & tomSelStartActive) |
| 2127 std::swap(sel.cpMin, sel.cpMax); | 2125 std::swap(sel.cpMin, sel.cpMax); |
| 2128 } | 2126 } |
| 2129 | 2127 |
| 2130 string16 OmniboxViewWin::GetSelectedText() const { | 2128 string16 OmniboxViewWin::GetSelectedText() const { |
| 2131 // Figure out the length of the selection. | |
| 2132 CHARRANGE sel; | 2129 CHARRANGE sel; |
| 2133 GetSel(sel); | 2130 GetSel(sel); |
| 2134 if (sel.cpMin == sel.cpMax) // GetSelText() crashes on NULL input. | |
| 2135 return string16(); | |
| 2136 | |
| 2137 // Grab the selected text. | |
| 2138 string16 str; | 2131 string16 str; |
| 2139 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); | 2132 if (sel.cpMin != sel.cpMax) |
| 2133 GetSelText(WriteInto(&str, sel.cpMax - sel.cpMin + 1)); |
| 2140 return str; | 2134 return str; |
| 2141 } | 2135 } |
| 2142 | 2136 |
| 2143 void OmniboxViewWin::SetSelection(LONG start, LONG end) { | 2137 void OmniboxViewWin::SetSelection(LONG start, LONG end) { |
| 2144 SetSel(start, end); | 2138 SetSel(start, end); |
| 2145 | 2139 |
| 2146 if (start <= end) | 2140 if (start <= end) |
| 2147 return; | 2141 return; |
| 2148 | 2142 |
| 2149 // We need to reverse the direction of the selection. | 2143 // We need to reverse the direction of the selection. |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2690 return omnibox_view; | 2684 return omnibox_view; |
| 2691 } | 2685 } |
| 2692 return new OmniboxViewWin(controller, | 2686 return new OmniboxViewWin(controller, |
| 2693 toolbar_model, | 2687 toolbar_model, |
| 2694 location_bar, | 2688 location_bar, |
| 2695 command_updater, | 2689 command_updater, |
| 2696 popup_window_mode, | 2690 popup_window_mode, |
| 2697 location_bar); | 2691 location_bar); |
| 2698 } | 2692 } |
| 2699 #endif | 2693 #endif |
| OLD | NEW |