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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 // kAutocompleteEditFontPixelSizeInPopup. They should be changed accordingly | 201 // kAutocompleteEditFontPixelSizeInPopup. They should be changed accordingly |
202 // if font size for autocomplete edit (in popup) change. | 202 // if font size for autocomplete edit (in popup) change. |
203 const int kAutocompleteVerticalMargin = 1; | 203 const int kAutocompleteVerticalMargin = 1; |
204 const int kAutocompleteVerticalMarginInPopup = 2; | 204 const int kAutocompleteVerticalMarginInPopup = 2; |
205 | 205 |
206 int GetEditFontPixelSize(bool popup_window_mode) { | 206 int GetEditFontPixelSize(bool popup_window_mode) { |
207 return popup_window_mode ? kAutocompleteEditFontPixelSizeInPopup : | 207 return popup_window_mode ? kAutocompleteEditFontPixelSizeInPopup : |
208 kAutocompleteEditFontPixelSize; | 208 kAutocompleteEditFontPixelSize; |
209 } | 209 } |
210 | 210 |
211 void DoCopy(const string16& text, const BookmarkNodeData* bookmark_node_data) { | |
212 ui::Clipboard* cb = views::ViewsDelegate::views_delegate->GetClipboard(); | |
213 ui::ScopedClipboardWriter scw(cb, ui::Clipboard::BUFFER_STANDARD); | |
214 scw.WriteText(text); | |
215 if (bookmark_node_data != NULL) | |
216 bookmark_node_data->WriteToClipboard(NULL); | |
217 } | |
218 | |
211 } // namespace | 219 } // namespace |
212 | 220 |
213 // static | 221 // static |
214 const char OmniboxViewViews::kViewClassName[] = "BrowserOmniboxViewViews"; | 222 const char OmniboxViewViews::kViewClassName[] = "BrowserOmniboxViewViews"; |
215 | 223 |
216 OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, | 224 OmniboxViewViews::OmniboxViewViews(OmniboxEditController* controller, |
217 ToolbarModel* toolbar_model, | 225 ToolbarModel* toolbar_model, |
218 Profile* profile, | 226 Profile* profile, |
219 CommandUpdater* command_updater, | 227 CommandUpdater* command_updater, |
220 bool popup_window_mode, | 228 bool popup_window_mode, |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 ui::Range selection_range; | 769 ui::Range selection_range; |
762 textfield_->GetSelectedRange(&selection_range); | 770 textfield_->GetSelectedRange(&selection_range); |
763 ui::Clipboard* cb = views::ViewsDelegate::views_delegate->GetClipboard(); | 771 ui::Clipboard* cb = views::ViewsDelegate::views_delegate->GetClipboard(); |
764 string16 selected_text; | 772 string16 selected_text; |
765 cb->ReadText(ui::Clipboard::BUFFER_STANDARD, &selected_text); | 773 cb->ReadText(ui::Clipboard::BUFFER_STANDARD, &selected_text); |
766 const string16 text = textfield_->text(); | 774 const string16 text = textfield_->text(); |
767 GURL url; | 775 GURL url; |
768 bool write_url; | 776 bool write_url; |
769 model()->AdjustTextForCopy(selection_range.GetMin(), selected_text == text, | 777 model()->AdjustTextForCopy(selection_range.GetMin(), selected_text == text, |
770 &selected_text, &url, &write_url); | 778 &selected_text, &url, &write_url); |
771 ui::ScopedClipboardWriter scw(cb, ui::Clipboard::BUFFER_STANDARD); | 779 BookmarkNodeData data; |
772 scw.WriteText(selected_text); | 780 data.ReadFromTuple(url, text); |
Peter Kasting
2012/09/11 21:52:59
Nit: If DoCopy() takes 4 args (what used to be her
dominich
2012/09/12 15:23:09
Done.
| |
773 if (write_url) { | 781 DoCopy(selected_text, write_url ? &data : NULL); |
774 BookmarkNodeData data; | |
775 data.ReadFromTuple(url, text); | |
776 data.WriteToClipboard(NULL); | |
777 } | |
778 } | 782 } |
779 | 783 |
780 void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) { | 784 void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) { |
781 ui::Range selection_range; | 785 ui::Range selection_range; |
782 textfield_->GetSelectedRange(&selection_range); | 786 textfield_->GetSelectedRange(&selection_range); |
783 string16 selected_text = textfield_->GetSelectedText(); | 787 string16 selected_text = textfield_->GetSelectedText(); |
784 const string16 text = textfield_->text(); | 788 const string16 text = textfield_->text(); |
785 GURL url; | 789 GURL url; |
786 bool write_url; | 790 bool write_url; |
787 model()->AdjustTextForCopy(selection_range.start(), selected_text == text, | 791 model()->AdjustTextForCopy(selection_range.start(), selected_text == text, |
788 &selected_text, &url, &write_url); | 792 &selected_text, &url, &write_url); |
789 data->SetString(selected_text); | 793 data->SetString(selected_text); |
790 if (write_url) | 794 if (write_url) |
791 data->SetURL(url, selected_text); | 795 data->SetURL(url, selected_text); |
792 } | 796 } |
793 | 797 |
794 void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { | 798 void OmniboxViewViews::UpdateContextMenu(ui::SimpleMenuModel* menu_contents) { |
795 // Minor note: We use IDC_ for command id here while the underlying textfield | 799 // Minor note: We use IDC_ for command id here while the underlying textfield |
796 // is using IDS_ for all its command ids. This is because views cannot depend | 800 // is using IDS_ for all its command ids. This is because views cannot depend |
797 // on IDC_ for now. | 801 // on IDC_ for now. |
798 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 802 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
799 IDS_EDIT_SEARCH_ENGINES); | 803 IDS_EDIT_SEARCH_ENGINES); |
800 | 804 |
805 if (chrome::search::IsInstantExtendedAPIEnabled( | |
806 location_bar_view_->profile())) { | |
807 int copy_position = menu_contents->GetIndexOfCommandId(IDS_APP_COPY); | |
808 DCHECK(copy_position >= 0); | |
809 menu_contents->InsertItemWithStringIdAt( | |
810 copy_position + 1, IDC_COPY_URL, IDS_COPY_URL); | |
811 } | |
812 | |
801 int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE); | 813 int paste_position = menu_contents->GetIndexOfCommandId(IDS_APP_PASTE); |
802 if (paste_position >= 0) | 814 DCHECK(paste_position >= 0); |
803 menu_contents->InsertItemWithStringIdAt( | 815 menu_contents->InsertItemWithStringIdAt( |
804 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); | 816 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
805 } | 817 } |
806 | 818 |
807 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { | 819 bool OmniboxViewViews::IsCommandIdEnabled(int command_id) const { |
808 return (command_id == IDS_PASTE_AND_GO) ? | 820 if (command_id == IDS_PASTE_AND_GO) { |
809 model()->CanPasteAndGo(GetClipboardText()) : | 821 return model()->CanPasteAndGo(GetClipboardText()); |
810 command_updater()->IsCommandEnabled(command_id); | 822 } else if (command_id == IDS_COPY_URL) { |
Peter Kasting
2012/09/11 21:52:59
Nit: No else after return.
dominich
2012/09/12 15:23:09
Done.
| |
823 return toolbar_model()->WouldReplaceSearchURLWithSearchTerms() && | |
824 !model()->user_input_in_progress(); | |
825 } | |
826 return command_updater()->IsCommandEnabled(command_id); | |
811 } | 827 } |
812 | 828 |
813 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { | 829 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { |
814 return command_id == IDS_PASTE_AND_GO; | 830 return command_id == IDS_PASTE_AND_GO; |
815 } | 831 } |
816 | 832 |
817 string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const { | 833 string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const { |
818 if (command_id == IDS_PASTE_AND_GO) { | 834 if (command_id == IDS_PASTE_AND_GO) { |
819 return l10n_util::GetStringUTF16( | 835 return l10n_util::GetStringUTF16( |
820 model()->IsPasteAndSearch(GetClipboardText()) ? | 836 model()->IsPasteAndSearch(GetClipboardText()) ? |
821 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); | 837 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); |
822 } | 838 } |
823 | 839 |
824 return string16(); | 840 return string16(); |
825 } | 841 } |
826 | 842 |
827 void OmniboxViewViews::ExecuteCommand(int command_id) { | 843 void OmniboxViewViews::ExecuteCommand(int command_id) { |
828 if (command_id == IDS_PASTE_AND_GO) { | 844 if (command_id == IDS_PASTE_AND_GO) |
829 model()->PasteAndGo(GetClipboardText()); | 845 model()->PasteAndGo(GetClipboardText()); |
830 return; | 846 else if (command_id == IDS_COPY_URL) |
831 } | 847 CopyURL(); |
832 | 848 else |
833 command_updater()->ExecuteCommand(command_id); | 849 command_updater()->ExecuteCommand(command_id); |
834 } | 850 } |
835 | 851 |
836 #if defined(OS_CHROMEOS) | 852 #if defined(OS_CHROMEOS) |
837 void OmniboxViewViews::CandidateWindowOpened( | 853 void OmniboxViewViews::CandidateWindowOpened( |
838 chromeos::input_method::InputMethodManager* manager) { | 854 chromeos::input_method::InputMethodManager* manager) { |
839 ime_candidate_window_open_ = true; | 855 ime_candidate_window_open_ = true; |
840 CloseOmniboxPopup(); | 856 CloseOmniboxPopup(); |
841 } | 857 } |
842 | 858 |
843 void OmniboxViewViews::CandidateWindowClosed( | 859 void OmniboxViewViews::CandidateWindowClosed( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 const ui::Range& range) { | 914 const ui::Range& range) { |
899 if (text != GetText()) | 915 if (text != GetText()) |
900 textfield_->SetText(text); | 916 textfield_->SetText(text); |
901 textfield_->SelectRange(range); | 917 textfield_->SelectRange(range); |
902 } | 918 } |
903 | 919 |
904 string16 OmniboxViewViews::GetSelectedText() const { | 920 string16 OmniboxViewViews::GetSelectedText() const { |
905 // TODO(oshima): Support instant, IME. | 921 // TODO(oshima): Support instant, IME. |
906 return textfield_->GetSelectedText(); | 922 return textfield_->GetSelectedText(); |
907 } | 923 } |
924 | |
925 void OmniboxViewViews::CopyURL() { | |
926 BookmarkNodeData data; | |
927 const string16& text = toolbar_model()->GetText(false); | |
928 data.ReadFromTuple(toolbar_model()->GetURL(), text); | |
929 DoCopy(text, &data); | |
930 } | |
OLD | NEW |