diff options
author | varunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 22:45:05 +0000 |
---|---|---|
committer | varunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 22:45:05 +0000 |
commit | f9ca3b174db251457252b3335235b8d1537c931f (patch) | |
tree | 164ef3e5776184c733f65e1083d4368c39f4c35b /ui/views/controls | |
parent | 3f46b13a5bf0dd30d601156eb007d0222ae87db3 (diff) | |
download | chromium_src-f9ca3b174db251457252b3335235b8d1537c931f.zip chromium_src-f9ca3b174db251457252b3335235b8d1537c931f.tar.gz chromium_src-f9ca3b174db251457252b3335235b8d1537c931f.tar.bz2 |
aura: Copy/Paste from Omnibox should restore http://
BUG=104333
TEST=none
Review URL: http://codereview.chromium.org/8996015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115207 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/controls')
5 files changed, 50 insertions, 7 deletions
diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc index 677c458..4008215 100644 --- a/ui/views/controls/textfield/native_textfield_views.cc +++ b/ui/views/controls/textfield/native_textfield_views.cc @@ -295,6 +295,9 @@ void NativeTextfieldViews::WriteDragDataForView(views::View* sender, DCHECK_NE(ui::DragDropTypes::DRAG_NONE, GetDragOperationsForView(sender, press_pt)); data->SetString(GetSelectedText()); + TextfieldController* controller = textfield_->GetController(); + if (controller) + controller->OnWriteDragData(data); } int NativeTextfieldViews::GetDragOperationsForView(views::View* sender, @@ -566,10 +569,10 @@ void NativeTextfieldViews::ExecuteCommand(int command_id) { switch (command_id) { case IDS_APP_CUT: if (editable) - text_changed = model_->Cut(); + text_changed = Cut(); break; case IDS_APP_COPY: - model_->Copy(); + Copy(); break; case IDS_APP_PASTE: if (editable) @@ -843,11 +846,11 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { break; case ui::VKEY_X: if (control && editable) - cursor_changed = text_changed = model_->Cut(); + cursor_changed = text_changed = Cut(); break; case ui::VKEY_C: if (control) - model_->Copy(); + Copy(); break; case ui::VKEY_V: if (control && editable) @@ -1020,6 +1023,26 @@ void NativeTextfieldViews::OnAfterUserAction() { controller->OnAfterUserAction(textfield_); } +bool NativeTextfieldViews::Cut() { + if (model_->Cut()) { + TextfieldController* controller = textfield_->GetController(); + if (controller) + controller->OnAfterCutOrCopy(); + return true; + } + return false; +} + +bool NativeTextfieldViews::Copy() { + if (model_->Copy()) { + TextfieldController* controller = textfield_->GetController(); + if (controller) + controller->OnAfterCutOrCopy(); + return true; + } + return false; +} + bool NativeTextfieldViews::Paste() { const bool success = model_->Paste(); diff --git a/ui/views/controls/textfield/native_textfield_views.h b/ui/views/controls/textfield/native_textfield_views.h index a60b931..d074dbf 100644 --- a/ui/views/controls/textfield/native_textfield_views.h +++ b/ui/views/controls/textfield/native_textfield_views.h @@ -210,6 +210,12 @@ class VIEWS_EXPORT NativeTextfieldViews : public TouchSelectionClientView, // Convenience method to call TextfieldController::OnAfterUserAction(); void OnAfterUserAction(); + // Calls |model_->Cut()| and notifies TextfieldController on success. + bool Cut(); + + // Calls |model_->Copy()| and notifies TextfieldController on success. + bool Copy(); + // Calls |model_->Paste()| and calls TextfieldController::ContentsChanged() // explicitly if paste succeeded. bool Paste(); diff --git a/ui/views/controls/textfield/textfield_controller.h b/ui/views/controls/textfield/textfield_controller.h index ef2bdda..c5cb2e5 100644 --- a/ui/views/controls/textfield/textfield_controller.h +++ b/ui/views/controls/textfield/textfield_controller.h @@ -8,6 +8,10 @@ #include "base/string16.h" +namespace ui { +class OSExchangeData; +} // namespace ui + namespace views { class KeyEvent; @@ -37,6 +41,13 @@ class TextfieldController { // It's currently only supported by Views implementation. virtual void OnAfterUserAction(Textfield* sender) {} + // Called after performing a Cut or Copy operation. + virtual void OnAfterCutOrCopy() {} + + // Called after the textfield has written drag data to give the controller a + // chance to modify the drag data. + virtual void OnWriteDragData(ui::OSExchangeData* data) {} + protected: virtual ~TextfieldController() {} }; diff --git a/ui/views/controls/textfield/textfield_views_model.cc b/ui/views/controls/textfield/textfield_views_model.cc index 77485c6..7df402d 100644 --- a/ui/views/controls/textfield/textfield_views_model.cc +++ b/ui/views/controls/textfield/textfield_views_model.cc @@ -526,11 +526,13 @@ bool TextfieldViewsModel::Cut() { return false; } -void TextfieldViewsModel::Copy() { +bool TextfieldViewsModel::Copy() { if (!HasCompositionText() && HasSelection()) { ui::ScopedClipboardWriter(views::ViewsDelegate::views_delegate ->GetClipboard()).WriteText(GetSelectedText()); + return true; } + return false; } bool TextfieldViewsModel::Paste() { diff --git a/ui/views/controls/textfield/textfield_views_model.h b/ui/views/controls/textfield/textfield_views_model.h index ce1d88f..e3fd7e8 100644 --- a/ui/views/controls/textfield/textfield_views_model.h +++ b/ui/views/controls/textfield/textfield_views_model.h @@ -190,8 +190,9 @@ class VIEWS_EXPORT TextfieldViewsModel { // if text has changed after cutting. bool Cut(); - // Copies the currently selected text and puts it to clipboard. - void Copy(); + // Copies the currently selected text and puts it to clipboard. Returns true + // if something was copied to the clipboard. + bool Copy(); // Pastes text from the clipboard at current cursor position. Returns true // if text has changed after pasting. |