OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/browser.h" | 5 #include "chrome/browser/browser.h" |
6 | 6 |
7 #include "app/animation.h" | 7 #include "app/animation.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/idle_timer.h" | 10 #include "base/idle_timer.h" |
| 11 #include "base/keyboard_codes.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/string_util.h" | 13 #include "base/string_util.h" |
13 #include "base/thread.h" | 14 #include "base/thread.h" |
14 #include "chrome/app/chrome_dll_resource.h" | 15 #include "chrome/app/chrome_dll_resource.h" |
15 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
16 #include "chrome/browser/browser_list.h" | 17 #include "chrome/browser/browser_list.h" |
17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/browser_shutdown.h" | 19 #include "chrome/browser/browser_shutdown.h" |
19 #include "chrome/browser/browser_window.h" | 20 #include "chrome/browser/browser_window.h" |
20 #include "chrome/browser/character_encoding.h" | 21 #include "chrome/browser/character_encoding.h" |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always | 1013 // TODO(devint): http://b/issue?id=1117225 Cut, Copy, and Paste are always |
1013 // enabled in the page menu regardless of whether the command will do | 1014 // enabled in the page menu regardless of whether the command will do |
1014 // anything. When someone selects the menu item, we just act as if they hit | 1015 // anything. When someone selects the menu item, we just act as if they hit |
1015 // the keyboard shortcut for the command by sending the associated key press | 1016 // the keyboard shortcut for the command by sending the associated key press |
1016 // to windows. The real fix to this bug is to disable the commands when they | 1017 // to windows. The real fix to this bug is to disable the commands when they |
1017 // won't do anything. We'll need something like an overall clipboard command | 1018 // won't do anything. We'll need something like an overall clipboard command |
1018 // manager to do that. | 1019 // manager to do that. |
1019 | 1020 |
1020 void Browser::Cut() { | 1021 void Browser::Cut() { |
1021 UserMetrics::RecordAction(L"Cut", profile_); | 1022 UserMetrics::RecordAction(L"Cut", profile_); |
1022 ui_controls::SendKeyPress(window()->GetNativeHandle(), L'X', true, false, | 1023 ui_controls::SendKeyPress(window()->GetNativeHandle(), base::VKEY_X, true, |
1023 false); | 1024 false, false); |
1024 } | 1025 } |
1025 | 1026 |
1026 void Browser::Copy() { | 1027 void Browser::Copy() { |
1027 UserMetrics::RecordAction(L"Copy", profile_); | 1028 UserMetrics::RecordAction(L"Copy", profile_); |
1028 ui_controls::SendKeyPress(window()->GetNativeHandle(), L'C', true, false, | 1029 ui_controls::SendKeyPress(window()->GetNativeHandle(), base::VKEY_C, true, |
1029 false); | 1030 false, false); |
1030 } | |
1031 | |
1032 void Browser::CopyCurrentPageURL() { | |
1033 UserMetrics::RecordAction(L"CopyURLToClipBoard", profile_); | |
1034 std::string url = GetSelectedTabContents()->GetURL().spec(); | |
1035 | |
1036 if (!::OpenClipboard(NULL)) { | |
1037 NOTREACHED(); | |
1038 return; | |
1039 } | |
1040 | |
1041 if (::EmptyClipboard()) { | |
1042 HGLOBAL text = ::GlobalAlloc(GMEM_MOVEABLE, url.size() + 1); | |
1043 LPSTR ptr = static_cast<LPSTR>(::GlobalLock(text)); | |
1044 memcpy(ptr, url.c_str(), url.size()); | |
1045 ptr[url.size()] = '\0'; | |
1046 ::GlobalUnlock(text); | |
1047 | |
1048 ::SetClipboardData(CF_TEXT, text); | |
1049 } | |
1050 | |
1051 if (!::CloseClipboard()) { | |
1052 NOTREACHED(); | |
1053 } | |
1054 } | 1031 } |
1055 | 1032 |
1056 void Browser::Paste() { | 1033 void Browser::Paste() { |
1057 UserMetrics::RecordAction(L"Paste", profile_); | 1034 UserMetrics::RecordAction(L"Paste", profile_); |
1058 ui_controls::SendKeyPress(window()->GetNativeHandle(), L'V', true, false, | 1035 ui_controls::SendKeyPress(window()->GetNativeHandle(), base::VKEY_V, true, |
1059 false); | 1036 false, false); |
1060 } | 1037 } |
1061 #endif // #if defined(OS_WIN) | 1038 #endif // #if defined(OS_WIN) |
1062 | 1039 |
1063 void Browser::Find() { | 1040 void Browser::Find() { |
1064 UserMetrics::RecordAction(L"Find", profile_); | 1041 UserMetrics::RecordAction(L"Find", profile_); |
1065 FindInPage(false, false); | 1042 FindInPage(false, false); |
1066 } | 1043 } |
1067 | 1044 |
1068 void Browser::FindNext() { | 1045 void Browser::FindNext() { |
1069 UserMetrics::RecordAction(L"FindNext", profile_); | 1046 UserMetrics::RecordAction(L"FindNext", profile_); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 case IDC_ENCODING_WINDOWS1256: | 1359 case IDC_ENCODING_WINDOWS1256: |
1383 case IDC_ENCODING_ISO88598: | 1360 case IDC_ENCODING_ISO88598: |
1384 case IDC_ENCODING_ISO88598I: | 1361 case IDC_ENCODING_ISO88598I: |
1385 case IDC_ENCODING_WINDOWS1255: | 1362 case IDC_ENCODING_WINDOWS1255: |
1386 case IDC_ENCODING_WINDOWS1258: OverrideEncoding(id); break; | 1363 case IDC_ENCODING_WINDOWS1258: OverrideEncoding(id); break; |
1387 | 1364 |
1388 #if defined(OS_WIN) | 1365 #if defined(OS_WIN) |
1389 // Clipboard commands | 1366 // Clipboard commands |
1390 case IDC_CUT: Cut(); break; | 1367 case IDC_CUT: Cut(); break; |
1391 case IDC_COPY: Copy(); break; | 1368 case IDC_COPY: Copy(); break; |
1392 case IDC_COPY_URL: CopyCurrentPageURL(); break; | |
1393 case IDC_PASTE: Paste(); break; | 1369 case IDC_PASTE: Paste(); break; |
1394 #endif | 1370 #endif |
1395 | 1371 |
1396 // Find-in-page | 1372 // Find-in-page |
1397 case IDC_FIND: Find(); break; | 1373 case IDC_FIND: Find(); break; |
1398 case IDC_FIND_NEXT: FindNext(); break; | 1374 case IDC_FIND_NEXT: FindNext(); break; |
1399 case IDC_FIND_PREVIOUS: FindPrevious(); break; | 1375 case IDC_FIND_PREVIOUS: FindPrevious(); break; |
1400 | 1376 |
1401 // Zoom | 1377 // Zoom |
1402 case IDC_ZOOM_PLUS: ZoomIn(); break; | 1378 case IDC_ZOOM_PLUS: ZoomIn(); break; |
(...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2800 /////////////////////////////////////////////////////////////////////////////// | 2776 /////////////////////////////////////////////////////////////////////////////// |
2801 // BrowserToolbarModel (private): | 2777 // BrowserToolbarModel (private): |
2802 | 2778 |
2803 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { | 2779 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { |
2804 // This |current_tab| can be NULL during the initialization of the | 2780 // This |current_tab| can be NULL during the initialization of the |
2805 // toolbar during window creation (i.e. before any tabs have been added | 2781 // toolbar during window creation (i.e. before any tabs have been added |
2806 // to the window). | 2782 // to the window). |
2807 TabContents* current_tab = browser_->GetSelectedTabContents(); | 2783 TabContents* current_tab = browser_->GetSelectedTabContents(); |
2808 return current_tab ? ¤t_tab->controller() : NULL; | 2784 return current_tab ? ¤t_tab->controller() : NULL; |
2809 } | 2785 } |
OLD | NEW |