Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit.cc

Issue 9154: Rewrote the clipboard API to be more concurrent. Added a helper class to make... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/scoped_clipboard_writer.cc ('k') | chrome/browser/download/download_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/autocomplete/autocomplete_edit.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit.h"
6 6
7 #include <locale> 7 #include <locale>
8 8
9 #include "base/base_drag_source.h" 9 #include "base/base_drag_source.h"
10 #include "base/clipboard.h" 10 #include "base/clipboard.h"
11 #include "base/gfx/skia_utils.h" 11 #include "base/gfx/skia_utils.h"
12 #include "base/iat_patch.h" 12 #include "base/iat_patch.h"
13 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "base/scoped_clipboard_writer.h"
14 #include "base/string_util.h" 15 #include "base/string_util.h"
15 #include "chrome/app/chrome_dll_resource.h" 16 #include "chrome/app/chrome_dll_resource.h"
16 #include "chrome/browser/autocomplete/autocomplete_popup.h" 17 #include "chrome/browser/autocomplete/autocomplete_popup.h"
17 #include "chrome/browser/autocomplete/edit_drop_target.h" 18 #include "chrome/browser/autocomplete/edit_drop_target.h"
18 #include "chrome/browser/autocomplete/keyword_provider.h" 19 #include "chrome/browser/autocomplete/keyword_provider.h"
19 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/controller.h" 21 #include "chrome/browser/controller.h"
21 #include "chrome/browser/drag_utils.h" 22 #include "chrome/browser/drag_utils.h"
22 #include "chrome/browser/profile.h" 23 #include "chrome/browser/profile.h"
23 #include "chrome/browser/tab_contents.h" 24 #include "chrome/browser/tab_contents.h"
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 } else { 1379 } else {
1379 context_menu_->RunMenuAt(point.x, point.y); 1380 context_menu_->RunMenuAt(point.x, point.y);
1380 } 1381 }
1381 } 1382 }
1382 1383
1383 void AutocompleteEditView::OnCopy() { 1384 void AutocompleteEditView::OnCopy() {
1384 const std::wstring text(GetSelectedText()); 1385 const std::wstring text(GetSelectedText());
1385 if (text.empty()) 1386 if (text.empty())
1386 return; 1387 return;
1387 1388
1388 ClipboardService* clipboard = g_browser_process->clipboard_service(); 1389 ScopedClipboardWriter scw(g_browser_process->clipboard_service());
1389 clipboard->Clear(); 1390 scw.WriteText(text);
1390 clipboard->WriteText(text);
1391 1391
1392 // Check if the user is copying the whole address bar. If they are, we 1392 // Check if the user is copying the whole address bar. If they are, we
1393 // assume they are trying to copy a URL and write this to the clipboard as a 1393 // assume they are trying to copy a URL and write this to the clipboard as a
1394 // hyperlink. 1394 // hyperlink.
1395 if (static_cast<int>(text.length()) < GetTextLength()) 1395 if (static_cast<int>(text.length()) < GetTextLength())
1396 return; 1396 return;
1397 1397
1398 // The entire control is selected. Let's see what the user typed. We can't 1398 // The entire control is selected. Let's see what the user typed. We can't
1399 // use model_->CurrentTextIsURL() or model_->GetDataForURLExport() because 1399 // use model_->CurrentTextIsURL() or model_->GetDataForURLExport() because
1400 // right now the user is probably holding down control to cause the copy, 1400 // right now the user is probably holding down control to cause the copy,
1401 // which will screw up our calculation of the desired_tld. 1401 // which will screw up our calculation of the desired_tld.
1402 GURL url; 1402 GURL url;
1403 if (model_->GetURLForText(text, &url)) 1403 if (model_->GetURLForText(text, &url))
1404 clipboard->WriteHyperlink(text, url.spec()); 1404 scw.WriteHyperlink(text, url.spec());
1405 } 1405 }
1406 1406
1407 void AutocompleteEditView::OnCut() { 1407 void AutocompleteEditView::OnCut() {
1408 OnCopy(); 1408 OnCopy();
1409 1409
1410 // This replace selection will have no effect (even on the undo stack) if the 1410 // This replace selection will have no effect (even on the undo stack) if the
1411 // current selection is empty. 1411 // current selection is empty.
1412 ReplaceSel(L"", true); 1412 ReplaceSel(L"", true);
1413 } 1413 }
1414 1414
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 } 2412 }
2413 2413
2414 void AutocompleteEditView::RepaintDropHighlight(int position) { 2414 void AutocompleteEditView::RepaintDropHighlight(int position) {
2415 if ((position != -1) && (position <= GetTextLength())) { 2415 if ((position != -1) && (position <= GetTextLength())) {
2416 const POINT min_loc(PosFromChar(position)); 2416 const POINT min_loc(PosFromChar(position));
2417 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, 2417 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_,
2418 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_}; 2418 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_};
2419 InvalidateRect(&highlight_bounds, false); 2419 InvalidateRect(&highlight_bounds, false);
2420 } 2420 }
2421 } 2421 }
OLDNEW
« no previous file with comments | « base/scoped_clipboard_writer.cc ('k') | chrome/browser/download/download_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698