OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/shell_dialogs.h" | 5 #include "chrome/browser/ui/shell_dialogs.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <commdlg.h> | 8 #include <commdlg.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/i18n/case_conversion.h" | 16 #include "base/i18n/case_conversion.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/string_split.h" | 18 #include "base/string_split.h" |
19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
21 #include "base/win/registry.h" | 21 #include "base/win/registry.h" |
22 #include "base/win/scoped_comptr.h" | 22 #include "base/win/scoped_comptr.h" |
23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
24 #include "chrome/browser/ui/color_chooser_dialog.h" | |
24 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
25 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
26 #include "grit/ui_strings.h" | 27 #include "grit/ui_strings.h" |
27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
28 | 29 |
29 // This function takes the output of a SaveAs dialog: a filename, a filter and | 30 // This function takes the output of a SaveAs dialog: a filename, a filter and |
30 // the extension originally suggested to the user (shown in the dialog box) and | 31 // the extension originally suggested to the user (shown in the dialog box) and |
31 // returns back the filename with the appropriate extension tacked on. If the | 32 // returns back the filename with the appropriate extension tacked on. If the |
32 // user requests an unknown extension and is not using the 'All files' filter, | 33 // user requests an unknown extension and is not using the 'All files' filter, |
33 // the suggested extension will be appended, otherwise we will leave the | 34 // the suggested extension will be appended, otherwise we will leave the |
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
933 } | 934 } |
934 } | 935 } |
935 } | 936 } |
936 return success; | 937 return success; |
937 } | 938 } |
938 | 939 |
939 // static | 940 // static |
940 SelectFileDialog* SelectFileDialog::Create(Listener* listener) { | 941 SelectFileDialog* SelectFileDialog::Create(Listener* listener) { |
941 return new SelectFileDialogImpl(listener); | 942 return new SelectFileDialogImpl(listener); |
942 } | 943 } |
944 | |
945 #if defined(ENABLE_INPUT_COLOR) | |
946 | |
947 COLORREF COLORREFFromWebColor(WebKit::WebColor color) { | |
948 uint8 r = (color >> 16) & 0xFF; | |
yosin_UTC9
2011/12/06 07:31:50
Could you use static_cast<uint8>(color >> 16) inst
| |
949 uint8 g = (color >> 8) & 0xFF; | |
950 uint8 b = (color >> 0) & 0xFF; | |
951 return RGB(r, g, b); | |
952 } | |
953 | |
954 WebKit::WebColor WebColorFromCOLORREF(COLORREF color) { | |
955 uint8 b = (color >> 16) & 0xFF; | |
yosin_UTC9
2011/12/06 07:31:50
It is better to use BYTE GetBValue(COLORREF), GetG
| |
956 uint8 g = (color >> 8) & 0xFF; | |
957 uint8 r = (color >> 0) & 0xFF; | |
958 return ((255 << 24) | (r << 16) | (g << 8) | b); | |
959 } | |
960 | |
961 class ColorChooserDialogImpl | |
962 : public ColorChooserDialog, | |
963 public BaseShellDialogImpl { | |
964 public: | |
965 explicit ColorChooserDialogImpl(Listener* listener); | |
966 | |
967 virtual bool IsRunning(HWND owning_hwnd) const; | |
yosin_UTC9
2011/12/06 07:31:50
Please put "OVERRIDE" before semi-colon for overri
| |
968 virtual void ListenerDestroyed(); | |
969 | |
970 virtual void SelectColor(WebKit::WebColor initial_color, | |
971 gfx::NativeWindow owning_window); | |
972 | |
973 private: | |
974 virtual ~ColorChooserDialogImpl(); | |
975 | |
976 struct ExecuteOpenParams { | |
977 ExecuteOpenParams(WebKit::WebColor color, | |
978 RunState run_state, | |
979 HWND owner) | |
980 : color(color), | |
981 run_state(run_state), | |
982 owner(owner) { | |
983 } | |
984 WebKit::WebColor color; | |
985 RunState run_state; | |
986 HWND owner; | |
987 }; | |
988 void ExecuteOpen(const ExecuteOpenParams& params); | |
989 void DidChooseColor(WebKit::WebColor color, RunState run_state); | |
990 | |
991 COLORREF custom_colors_[16]; | |
yosin_UTC9
2011/12/06 07:31:50
Where does number 16 come from? We may want to hav
| |
992 Listener* listener_; | |
993 }; | |
994 | |
995 ColorChooserDialogImpl::ColorChooserDialogImpl(Listener* listener) | |
996 : listener_(listener), | |
997 BaseShellDialogImpl() { | |
998 DCHECK(listener_); | |
999 } | |
1000 | |
1001 ColorChooserDialogImpl::~ColorChooserDialogImpl() { | |
1002 } | |
1003 | |
1004 bool ColorChooserDialogImpl::IsRunning(HWND owning_hwnd) const { | |
1005 return listener_ && IsRunningDialogForOwner(owning_hwnd); | |
1006 } | |
1007 | |
1008 void ColorChooserDialogImpl::ListenerDestroyed() { | |
1009 // Our associated listener has gone away, so we shouldn't call back to it if | |
1010 // our worker thread returns after the listener is dead. | |
1011 listener_ = NULL; | |
1012 } | |
1013 | |
1014 void ColorChooserDialogImpl::SelectColor(WebKit::WebColor initial_color, | |
1015 gfx::NativeWindow owning_window) { | |
1016 ExecuteOpenParams execute_params(initial_color, BeginRun(owning_window), | |
1017 owning_window); | |
1018 execute_params.run_state.dialog_thread->message_loop()->PostTask(FROM_HERE, | |
1019 NewRunnableMethod(this, &ColorChooserDialogImpl::ExecuteOpen, | |
1020 execute_params)); | |
1021 } | |
1022 | |
1023 void ColorChooserDialogImpl::ExecuteOpen(const ExecuteOpenParams& params) { | |
1024 COLORREF color = COLORREFFromWebColor(params.color); | |
1025 CHOOSECOLOR cc; | |
1026 cc.lStructSize = sizeof(CHOOSECOLOR); | |
1027 cc.hwndOwner = params.owner; | |
1028 cc.rgbResult = color; | |
1029 cc.lpCustColors = custom_colors_; | |
1030 cc.Flags = CC_FULLOPEN | CC_RGBINIT; | |
1031 bool success = !!ChooseColor(&cc); | |
1032 DisableOwner(cc.hwndOwner); | |
1033 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
1034 NewRunnableMethod(this, &ColorChooserDialogImpl::DidChooseColor, | |
1035 WebColorFromCOLORREF(cc.rgbResult), | |
1036 params.run_state)); | |
1037 } | |
1038 | |
1039 void ColorChooserDialogImpl::DidChooseColor(WebKit::WebColor color, | |
1040 RunState run_state) { | |
1041 if (!listener_) | |
1042 return; | |
1043 listener_->DidChooseColor(color); | |
1044 EndRun(run_state); | |
1045 } | |
1046 | |
1047 // static | |
1048 ColorChooserDialog* ColorChooserDialog::Create(Listener* listener) { | |
1049 return new ColorChooserDialogImpl(listener); | |
1050 } | |
1051 | |
1052 #endif // defined(ENABLE_INPUT_COLOR) | |
1053 | |
OLD | NEW |