| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // kAutocompleteEditFontPixelSizeInPopup. They should be changed accordingly | 108 // kAutocompleteEditFontPixelSizeInPopup. They should be changed accordingly |
| 109 // if font size for autocomplete edit (in popup) change. | 109 // if font size for autocomplete edit (in popup) change. |
| 110 const int kAutocompleteVerticalMargin = 1; | 110 const int kAutocompleteVerticalMargin = 1; |
| 111 const int kAutocompleteVerticalMarginInPopup = 2; | 111 const int kAutocompleteVerticalMarginInPopup = 2; |
| 112 | 112 |
| 113 int GetEditFontPixelSize(bool popup_window_mode) { | 113 int GetEditFontPixelSize(bool popup_window_mode) { |
| 114 return popup_window_mode ? kAutocompleteEditFontPixelSizeInPopup : | 114 return popup_window_mode ? kAutocompleteEditFontPixelSizeInPopup : |
| 115 kAutocompleteEditFontPixelSize; | 115 kAutocompleteEditFontPixelSize; |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Copies |selected_text| as text to the primary clipboard. If |write_url| is | 118 // Copies |selected_text| as text to the primary clipboard. |
| 119 // true, this will also write |url| and |text| to the clipboard as a well-formed | 119 void DoCopyText(const string16& selected_text) { |
| 120 // URL. | 120 ui::ScopedClipboardWriter scw(ui::Clipboard::GetForCurrentThread(), |
| 121 void DoCopy(const string16& selected_text, | 121 ui::Clipboard::BUFFER_STANDARD); |
| 122 bool write_url, | |
| 123 const GURL& url, | |
| 124 const string16& text) { | |
| 125 ui::Clipboard* cb = ui::Clipboard::GetForCurrentThread(); | |
| 126 ui::ScopedClipboardWriter scw(cb, ui::Clipboard::BUFFER_STANDARD); | |
| 127 scw.WriteText(selected_text); | 122 scw.WriteText(selected_text); |
| 128 if (write_url) { | 123 } |
| 129 BookmarkNodeData data; | 124 |
| 130 data.ReadFromTuple(url, text); | 125 // This will write |url| and |text| to the clipboard as a well-formed URL. |
| 131 data.WriteToClipboard(NULL); | 126 void DoCopyURL(const GURL& url, const string16& text) { |
| 132 } | 127 BookmarkNodeData data; |
| 128 data.ReadFromTuple(url, text); |
| 129 data.WriteToClipboard(NULL); |
| 133 } | 130 } |
| 134 | 131 |
| 135 } // namespace | 132 } // namespace |
| 136 | 133 |
| 137 // Textfield for autocomplete that intercepts events that are necessary | 134 // Textfield for autocomplete that intercepts events that are necessary |
| 138 // for OmniboxViewViews. | 135 // for OmniboxViewViews. |
| 139 class OmniboxViewViews::AutocompleteTextfield : public views::Textfield { | 136 class OmniboxViewViews::AutocompleteTextfield : public views::Textfield { |
| 140 public: | 137 public: |
| 141 AutocompleteTextfield(OmniboxViewViews* omnibox_view, | 138 AutocompleteTextfield(OmniboxViewViews* omnibox_view, |
| 142 LocationBarView* location_bar_view) | 139 LocationBarView* location_bar_view) |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 ui::Range selection_range; | 760 ui::Range selection_range; |
| 764 textfield_->GetSelectedRange(&selection_range); | 761 textfield_->GetSelectedRange(&selection_range); |
| 765 ui::Clipboard* cb = ui::Clipboard::GetForCurrentThread(); | 762 ui::Clipboard* cb = ui::Clipboard::GetForCurrentThread(); |
| 766 string16 selected_text; | 763 string16 selected_text; |
| 767 cb->ReadText(ui::Clipboard::BUFFER_STANDARD, &selected_text); | 764 cb->ReadText(ui::Clipboard::BUFFER_STANDARD, &selected_text); |
| 768 const string16 text = textfield_->text(); | 765 const string16 text = textfield_->text(); |
| 769 GURL url; | 766 GURL url; |
| 770 bool write_url; | 767 bool write_url; |
| 771 model()->AdjustTextForCopy(selection_range.GetMin(), selected_text == text, | 768 model()->AdjustTextForCopy(selection_range.GetMin(), selected_text == text, |
| 772 &selected_text, &url, &write_url); | 769 &selected_text, &url, &write_url); |
| 773 DoCopy(selected_text, write_url, url, text); | 770 if (write_url) |
| 771 DoCopyURL(url, selected_text); |
| 772 else |
| 773 DoCopyText(selected_text); |
| 774 } | 774 } |
| 775 | 775 |
| 776 void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) { | 776 void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) { |
| 777 ui::Range selection_range; | 777 ui::Range selection_range; |
| 778 textfield_->GetSelectedRange(&selection_range); | 778 textfield_->GetSelectedRange(&selection_range); |
| 779 string16 selected_text = textfield_->GetSelectedText(); | 779 string16 selected_text = textfield_->GetSelectedText(); |
| 780 const string16 text = textfield_->text(); | 780 const string16 text = textfield_->text(); |
| 781 GURL url; | 781 GURL url; |
| 782 bool write_url; | 782 bool write_url; |
| 783 model()->AdjustTextForCopy(selection_range.start(), selected_text == text, | 783 model()->AdjustTextForCopy(selection_range.start(), selected_text == text, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 textfield_->SetText(text); | 946 textfield_->SetText(text); |
| 947 textfield_->SelectRange(range); | 947 textfield_->SelectRange(range); |
| 948 } | 948 } |
| 949 | 949 |
| 950 string16 OmniboxViewViews::GetSelectedText() const { | 950 string16 OmniboxViewViews::GetSelectedText() const { |
| 951 // TODO(oshima): Support instant, IME. | 951 // TODO(oshima): Support instant, IME. |
| 952 return textfield_->GetSelectedText(); | 952 return textfield_->GetSelectedText(); |
| 953 } | 953 } |
| 954 | 954 |
| 955 void OmniboxViewViews::CopyURL() { | 955 void OmniboxViewViews::CopyURL() { |
| 956 const string16& text = toolbar_model()->GetText(false); | 956 DoCopyURL(toolbar_model()->GetURL(), toolbar_model()->GetText(false)); |
| 957 DoCopy(text, true, toolbar_model()->GetURL(), text); | |
| 958 } | 957 } |
| 959 | 958 |
| 960 void OmniboxViewViews::OnPaste() { | 959 void OmniboxViewViews::OnPaste() { |
| 961 // Replace the selection if we have something to paste. | 960 // Replace the selection if we have something to paste. |
| 962 const string16 text(GetClipboardText()); | 961 const string16 text(GetClipboardText()); |
| 963 if (!text.empty()) { | 962 if (!text.empty()) { |
| 964 // Record this paste, so we can do different behavior. | 963 // Record this paste, so we can do different behavior. |
| 965 model()->on_paste(); | 964 model()->on_paste(); |
| 966 // Force a Paste operation to trigger the text_changed code in | 965 // Force a Paste operation to trigger the text_changed code in |
| 967 // OnAfterPossibleChange(), even if identical contents are pasted into the | 966 // OnAfterPossibleChange(), even if identical contents are pasted into the |
| 968 // text box. | 967 // text box. |
| 969 text_before_change_.clear(); | 968 text_before_change_.clear(); |
| 970 textfield_->ReplaceSelection(text); | 969 textfield_->ReplaceSelection(text); |
| 971 } | 970 } |
| 972 } | 971 } |
| OLD | NEW |