| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "ui/base/win/open_file_name_win.h" | 5 #include "ui/base/win/open_file_name_win.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/macros.h" | |
| 9 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 10 #include "base/win/windows_version.h" | |
| 11 | 9 |
| 12 namespace ui { | 10 namespace ui { |
| 13 namespace win { | 11 namespace win { |
| 14 | 12 |
| 15 namespace { | |
| 16 | |
| 17 // Ensures that the Save As dialog is on-screen. | |
| 18 UINT_PTR CALLBACK SaveAsDialogHook(HWND dialog, UINT message, | |
| 19 WPARAM wparam, LPARAM lparam) { | |
| 20 static const UINT kPrivateMessage = 0x2F3F; | |
| 21 switch (message) { | |
| 22 case WM_INITDIALOG: { | |
| 23 // Do nothing here. Just post a message to defer actual processing. | |
| 24 ::PostMessage(dialog, kPrivateMessage, 0, 0); | |
| 25 return TRUE; | |
| 26 } | |
| 27 case kPrivateMessage: { | |
| 28 // The dialog box is the parent of the current handle. | |
| 29 HWND real_dialog = ::GetParent(dialog); | |
| 30 | |
| 31 // Retrieve the final size. | |
| 32 RECT dialog_rect; | |
| 33 ::GetWindowRect(real_dialog, &dialog_rect); | |
| 34 | |
| 35 // Verify that the upper left corner is visible. | |
| 36 POINT point = { dialog_rect.left, dialog_rect.top }; | |
| 37 HMONITOR monitor1 = ::MonitorFromPoint(point, MONITOR_DEFAULTTONULL); | |
| 38 point.x = dialog_rect.right; | |
| 39 point.y = dialog_rect.bottom; | |
| 40 | |
| 41 // Verify that the lower right corner is visible. | |
| 42 HMONITOR monitor2 = ::MonitorFromPoint(point, MONITOR_DEFAULTTONULL); | |
| 43 if (monitor1 && monitor2) | |
| 44 return 0; | |
| 45 | |
| 46 // Some part of the dialog box is not visible, fix it by moving is to the | |
| 47 // client rect position of the browser window. | |
| 48 HWND parent_window = ::GetParent(real_dialog); | |
| 49 if (!parent_window) | |
| 50 return 0; | |
| 51 WINDOWINFO parent_info; | |
| 52 parent_info.cbSize = sizeof(WINDOWINFO); | |
| 53 ::GetWindowInfo(parent_window, &parent_info); | |
| 54 ::SetWindowPos( | |
| 55 real_dialog, | |
| 56 NULL, | |
| 57 parent_info.rcClient.left, | |
| 58 parent_info.rcClient.top, | |
| 59 0, | |
| 60 0, // Size. | |
| 61 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER); | |
| 62 | |
| 63 return 0; | |
| 64 } | |
| 65 } | |
| 66 return 0; | |
| 67 } | |
| 68 | |
| 69 } // namespace | |
| 70 | |
| 71 OpenFileName::OpenFileName(HWND parent_window, DWORD flags) { | 13 OpenFileName::OpenFileName(HWND parent_window, DWORD flags) { |
| 72 ::ZeroMemory(&openfilename_, sizeof(openfilename_)); | 14 ::ZeroMemory(&openfilename_, sizeof(openfilename_)); |
| 73 openfilename_.lStructSize = sizeof(openfilename_); | 15 openfilename_.lStructSize = sizeof(openfilename_); |
| 74 | 16 |
| 75 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, | 17 // According to http://support.microsoft.com/?scid=kb;en-us;222003&x=8&y=12, |
| 76 // The lpstrFile Buffer MUST be NULL Terminated. | 18 // The lpstrFile Buffer MUST be NULL Terminated. |
| 77 filename_buffer_[0] = 0; | 19 filename_buffer_[0] = 0; |
| 78 openfilename_.lpstrFile = filename_buffer_; | 20 openfilename_.lpstrFile = filename_buffer_; |
| 79 openfilename_.nMaxFile = arraysize(filename_buffer_); | 21 openfilename_.nMaxFile = arraysize(filename_buffer_); |
| 80 | 22 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 62 |
| 121 if (initial_filename.empty()) | 63 if (initial_filename.empty()) |
| 122 return; | 64 return; |
| 123 | 65 |
| 124 // The filename is ignored if no initial directory is supplied. | 66 // The filename is ignored if no initial directory is supplied. |
| 125 base::wcslcpy(filename_buffer_, | 67 base::wcslcpy(filename_buffer_, |
| 126 initial_filename.value().c_str(), | 68 initial_filename.value().c_str(), |
| 127 arraysize(filename_buffer_)); | 69 arraysize(filename_buffer_)); |
| 128 } | 70 } |
| 129 | 71 |
| 130 void OpenFileName::MaybeInstallWindowPositionHookForSaveAsOnXP() { | |
| 131 if (base::win::GetVersion() >= base::win::VERSION_VISTA) | |
| 132 return; | |
| 133 | |
| 134 openfilename_.Flags |= OFN_ENABLEHOOK; | |
| 135 DCHECK(!openfilename_.lpfnHook); | |
| 136 openfilename_.lpfnHook = &SaveAsDialogHook; | |
| 137 } | |
| 138 | |
| 139 base::FilePath OpenFileName::GetSingleResult() { | 72 base::FilePath OpenFileName::GetSingleResult() { |
| 140 base::FilePath directory; | 73 base::FilePath directory; |
| 141 std::vector<base::FilePath> filenames; | 74 std::vector<base::FilePath> filenames; |
| 142 GetResult(&directory, &filenames); | 75 GetResult(&directory, &filenames); |
| 143 if (filenames.size() != 1) | 76 if (filenames.size() != 1) |
| 144 return base::FilePath(); | 77 return base::FilePath(); |
| 145 return directory.Append(filenames[0]); | 78 return directory.Append(filenames[0]); |
| 146 } | 79 } |
| 147 | 80 |
| 148 void OpenFileName::GetResult(base::FilePath* directory, | 81 void OpenFileName::GetResult(base::FilePath* directory, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 std::make_tuple(base::string16(display_string, display_string_end), | 156 std::make_tuple(base::string16(display_string, display_string_end), |
| 224 base::string16(pattern, pattern_end))); | 157 base::string16(pattern, pattern_end))); |
| 225 display_string = pattern_end + 1; | 158 display_string = pattern_end + 1; |
| 226 } | 159 } |
| 227 | 160 |
| 228 return filters; | 161 return filters; |
| 229 } | 162 } |
| 230 | 163 |
| 231 } // namespace win | 164 } // namespace win |
| 232 } // namespace ui | 165 } // namespace ui |
| OLD | NEW |