summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-31 20:39:02 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-31 20:39:02 +0000
commitfd85ad650d68309b965dbc9f3d6823cf2754349c (patch)
tree28b98629e02b2e05ec74272146f249ca62a164da /app
parentce072a7181ea5d58133e33654133236f5d9f5551 (diff)
downloadchromium_src-fd85ad650d68309b965dbc9f3d6823cf2754349c.zip
chromium_src-fd85ad650d68309b965dbc9f3d6823cf2754349c.tar.gz
chromium_src-fd85ad650d68309b965dbc9f3d6823cf2754349c.tar.bz2
Move app/win_util to app/win and fix the namespace usage.
Split out the two classes: ScopedComInitializer and ScopedCOMem (which I renamed) to separate files. I removed the win_util_path file which had one function in it and moved the function to win_util. Somehow, this was getting picked up by the nacl64 build and the call in sandbox_policy was then not being defined. I just implemented the function in-plcae since it's just a simple wrapper around a Windows API call. TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/6013009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70343 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/app.gyp2
-rw-r--r--app/app_base.gypi11
-rw-r--r--app/win/scoped_co_mem.h49
-rw-r--r--app/win/scoped_com_initializer.h60
-rw-r--r--app/win/win_util.cc (renamed from app/win_util.cc)46
-rw-r--r--app/win/win_util.h (renamed from app/win_util.h)101
-rw-r--r--app/win/win_util_unittest.cc59
-rw-r--r--app/win_util_path.cc22
-rw-r--r--app/win_util_unittest.cc84
9 files changed, 225 insertions, 209 deletions
diff --git a/app/app.gyp b/app/app.gyp
index e34f161..bac326b 100644
--- a/app/app.gyp
+++ b/app/app.gyp
@@ -58,7 +58,7 @@
'tree_node_iterator_unittest.cc',
'tree_node_model_unittest.cc',
'view_prop_unittest.cc',
- 'win_util_unittest.cc',
+ 'win/win_util_unittest.cc',
],
'include_dirs': [
'..',
diff --git a/app/app_base.gypi b/app/app_base.gypi
index 2581bdb..6bcad0e 100644
--- a/app/app_base.gypi
+++ b/app/app_base.gypi
@@ -32,13 +32,6 @@
'tree_node_model.h',
],
'conditions': [
- ['OS=="win"', {
- 'sources': [
- 'win_util.cc',
- 'win_util.h',
- 'win_util_path.cc',
- ],
- }],
['OS!="linux" and OS!="freebsd" and OS!="openbsd"', {
'sources!': [
'gtk_dnd_util.cc',
@@ -238,12 +231,16 @@
'win/hwnd_util.h',
'win/iat_patch_function.cc',
'win/iat_patch_function.h',
+ 'win/scoped_co_mem.h',
+ 'win/scoped_com_initializer.h',
'win/scoped_prop.cc',
'win/scoped_prop.h',
'win/shell.cc',
'win/shell.h',
'win/window_impl.cc',
'win/window_impl.h',
+ 'win/win_util.cc',
+ 'win/win_util.h',
'x11_util.cc',
'x11_util.h',
'x11_util_internal.h',
diff --git a/app/win/scoped_co_mem.h b/app/win/scoped_co_mem.h
new file mode 100644
index 0000000..a6017fa
--- /dev/null
+++ b/app/win/scoped_co_mem.h
@@ -0,0 +1,49 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APP_WIN_SCOPED_CO_MEM_H_
+#define APP_WIN_SCOPED_CO_MEM_H_
+#pragma once
+
+#include <objbase.h>
+
+#include "base/basictypes.h"
+
+namespace app {
+namespace win {
+
+// Simple scoped memory releaser class for COM allocated memory.
+// Example:
+// app::win::ScopedCoMem<ITEMIDLIST> file_item;
+// SHGetSomeInfo(&file_item, ...);
+// ...
+// return; <-- memory released
+template<typename T>
+class ScopedCoMem {
+ public:
+ explicit ScopedCoMem() : mem_ptr_(NULL) {}
+
+ ~ScopedCoMem() {
+ if (mem_ptr_)
+ CoTaskMemFree(mem_ptr_);
+ }
+
+ T** operator&() { // NOLINT
+ return &mem_ptr_;
+ }
+
+ operator T*() {
+ return mem_ptr_;
+ }
+
+ private:
+ T* mem_ptr_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedCoMem);
+};
+
+} // namespace win
+} // namespace app
+
+#endif // APP_WIN_SCOPED_CO_MEM_H_
diff --git a/app/win/scoped_com_initializer.h b/app/win/scoped_com_initializer.h
new file mode 100644
index 0000000..3a2cf55
--- /dev/null
+++ b/app/win/scoped_com_initializer.h
@@ -0,0 +1,60 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APP_WIN_SCOPED_COM_INITIALIZER_H_
+#define APP_WIN_SCOPED_COM_INITIALIZER_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+
+#include <objbase.h>
+
+namespace app {
+namespace win {
+
+// Initializes COM in the constructor (STA), and uninitializes COM in the
+// destructor.
+class ScopedCOMInitializer {
+ public:
+ ScopedCOMInitializer() : hr_(CoInitialize(NULL)) {
+ }
+
+ ScopedCOMInitializer::~ScopedCOMInitializer() {
+ if (SUCCEEDED(hr_))
+ CoUninitialize();
+ }
+
+ private:
+ HRESULT hr_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedCOMInitializer);
+};
+
+} // namespace win
+} // namespace app
+
+#else
+
+namespace app {
+namespace win {
+
+// Do-nothing class for other platforms.
+class ScopedCOMInitializer {
+ public:
+ ScopedCOMInitializer() {}
+ ~ScopedCOMInitializer() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScopedCOMInitializer);
+};
+
+} // namespace win
+} // namespace app
+
+#endif
+
+#endif // APP_WIN_SCOPED_COM_INITIALIZER_H_
diff --git a/app/win_util.cc b/app/win/win_util.cc
index 3ed9842..f1ac107 100644
--- a/app/win_util.cc
+++ b/app/win/win_util.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "app/win_util.h"
+#include "app/win/win_util.h"
#include <commdlg.h>
#include <shellapi.h>
@@ -23,14 +23,15 @@
#include "base/win/scoped_hdc.h"
#include "base/win/win_util.h"
#include "gfx/codec/png_codec.h"
+#include "gfx/font.h"
#include "gfx/gdi_util.h"
-namespace win_util {
+namespace app {
+namespace win {
const int kAutoHideTaskbarThicknessPx = 2;
-std::wstring FormatSystemTime(const SYSTEMTIME& time,
- const std::wstring& format) {
+string16 FormatSystemTime(const SYSTEMTIME& time, const string16& format) {
// If the format string is empty, just use the default format.
LPCTSTR format_ptr = NULL;
if (!format.empty())
@@ -39,15 +40,14 @@ std::wstring FormatSystemTime(const SYSTEMTIME& time,
int buffer_size = GetTimeFormat(LOCALE_USER_DEFAULT, NULL, &time, format_ptr,
NULL, 0);
- std::wstring output;
+ string16 output;
GetTimeFormat(LOCALE_USER_DEFAULT, NULL, &time, format_ptr,
WriteInto(&output, buffer_size), buffer_size);
return output;
}
-std::wstring FormatSystemDate(const SYSTEMTIME& date,
- const std::wstring& format) {
+string16 FormatSystemDate(const SYSTEMTIME& date, const string16& format) {
// If the format string is empty, just use the default format.
LPCTSTR format_ptr = NULL;
if (!format.empty())
@@ -56,13 +56,26 @@ std::wstring FormatSystemDate(const SYSTEMTIME& date,
int buffer_size = GetDateFormat(LOCALE_USER_DEFAULT, NULL, &date, format_ptr,
NULL, 0);
- std::wstring output;
+ string16 output;
GetDateFormat(LOCALE_USER_DEFAULT, NULL, &date, format_ptr,
WriteInto(&output, buffer_size), buffer_size);
return output;
}
+bool ConvertToLongPath(const string16& short_path,
+ string16* long_path) {
+ wchar_t long_path_buf[MAX_PATH];
+ DWORD return_value = GetLongPathName(short_path.c_str(), long_path_buf,
+ MAX_PATH);
+ if (return_value != 0 && return_value < MAX_PATH) {
+ *long_path = long_path_buf;
+ return true;
+ }
+
+ return false;
+}
+
bool IsDoubleClick(const POINT& origin,
const POINT& current,
DWORD elapsed_time) {
@@ -241,7 +254,7 @@ bool IsWindowActive(HWND hwnd) {
((info.dwWindowStatus & WS_ACTIVECAPTION) != 0);
}
-bool IsReservedName(const std::wstring& filename) {
+bool IsReservedName(const string16& filename) {
// This list is taken from the MSDN article "Naming a file"
// http://msdn2.microsoft.com/en-us/library/aa365247(VS.85).aspx
// I also added clock$ because GetSaveFileName seems to consider it as a
@@ -251,14 +264,14 @@ bool IsReservedName(const std::wstring& filename) {
L"com6", L"com7", L"com8", L"com9", L"lpt1", L"lpt2", L"lpt3", L"lpt4",
L"lpt5", L"lpt6", L"lpt7", L"lpt8", L"lpt9", L"clock$"
};
- std::wstring filename_lower = StringToLowerASCII(filename);
+ string16 filename_lower = StringToLowerASCII(filename);
for (int i = 0; i < arraysize(known_devices); ++i) {
// Exact match.
if (filename_lower == known_devices[i])
return true;
// Starts with "DEVICE.".
- if (filename_lower.find(std::wstring(known_devices[i]) + L".") == 0)
+ if (filename_lower.find(string16(known_devices[i]) + L".") == 0)
return true;
}
@@ -280,8 +293,8 @@ bool IsReservedName(const std::wstring& filename) {
// RTL locale, we need to make sure that LTR strings are rendered correctly by
// adding the appropriate Unicode directionality marks.
int MessageBox(HWND hwnd,
- const std::wstring& text,
- const std::wstring& caption,
+ const string16& text,
+ const string16& caption,
UINT flags) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoMessageBox))
return IDOK;
@@ -290,11 +303,11 @@ int MessageBox(HWND hwnd,
if (base::i18n::IsRTL())
actual_flags |= MB_RIGHT | MB_RTLREADING;
- std::wstring localized_text = text;
+ string16 localized_text = text;
base::i18n::AdjustStringForLocaleDirection(&localized_text);
const wchar_t* text_ptr = localized_text.c_str();
- std::wstring localized_caption = caption;
+ string16 localized_caption = caption;
base::i18n::AdjustStringForLocaleDirection(&localized_caption);
const wchar_t* caption_ptr = localized_caption.c_str();
@@ -309,4 +322,5 @@ gfx::Font GetWindowTitleFont() {
return gfx::Font(caption_font);
}
-} // namespace win_util
+} // namespace win
+} // namespace app
diff --git a/app/win_util.h b/app/win/win_util.h
index 2fcd86b..71b0f78 100644
--- a/app/win_util.h
+++ b/app/win/win_util.h
@@ -2,103 +2,45 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef APP_WIN_UTIL_H_
-#define APP_WIN_UTIL_H_
+#ifndef APP_WIN_WIN_UTIL_H_
+#define APP_WIN_WIN_UTIL_H_
#pragma once
-#include <objbase.h>
+#include <windows.h>
-#include <string>
#include <vector>
-#include "base/fix_wp64.h"
-#include "base/scoped_handle.h"
-#include "gfx/font.h"
-#include "gfx/rect.h"
+#include "base/string16.h"
class FilePath;
-namespace win_util {
-
-// Import ScopedHandle and friends into this namespace for backwards
-// compatibility. TODO(darin): clean this up!
-using ::ScopedHandle;
-using ::ScopedBitmap;
-
-// Simple scoped memory releaser class for COM allocated memory.
-// Example:
-// CoMemReleaser<ITEMIDLIST> file_item;
-// SHGetSomeInfo(&file_item, ...);
-// ...
-// return; <-- memory released
-template<typename T>
-class CoMemReleaser {
- public:
- explicit CoMemReleaser() : mem_ptr_(NULL) {}
-
- ~CoMemReleaser() {
- if (mem_ptr_)
- CoTaskMemFree(mem_ptr_);
- }
-
- T** operator&() { // NOLINT
- return &mem_ptr_;
- }
-
- operator T*() {
- return mem_ptr_;
- }
-
- private:
- T* mem_ptr_;
-
- DISALLOW_COPY_AND_ASSIGN(CoMemReleaser);
-};
-
-// Initializes COM in the constructor (STA), and uninitializes COM in the
-// destructor.
-class ScopedCOMInitializer {
- public:
- ScopedCOMInitializer() : hr_(CoInitialize(NULL)) {
- }
-
- ScopedCOMInitializer::~ScopedCOMInitializer() {
- if (SUCCEEDED(hr_))
- CoUninitialize();
- }
-
- // Returns the error code from CoInitialize(NULL)
- // (called in constructor)
- inline HRESULT error_code() const {
- return hr_;
- }
-
- protected:
- HRESULT hr_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ScopedCOMInitializer);
-};
+namespace gfx {
+class Font;
+class Rect;
+}
+
+namespace app {
+namespace win {
// Creates a string interpretation of the time of day represented by the given
// SYSTEMTIME that's appropriate for the user's default locale.
// Format can be an empty string (for the default format), or a "format picture"
// as specified in the Windows documentation for GetTimeFormat().
-std::wstring FormatSystemTime(const SYSTEMTIME& time,
- const std::wstring& format);
+string16 FormatSystemTime(const SYSTEMTIME& time,
+ const string16& format);
// Creates a string interpretation of the date represented by the given
// SYSTEMTIME that's appropriate for the user's default locale.
// Format can be an empty string (for the default format), or a "format picture"
// as specified in the Windows documentation for GetDateFormat().
-std::wstring FormatSystemDate(const SYSTEMTIME& date,
- const std::wstring& format);
+string16 FormatSystemDate(const SYSTEMTIME& date,
+ const string16& format);
// Returns the long path name given a short path name. A short path name
// is a path that follows the 8.3 convention and has ~x in it. If the
// path is already a long path name, the function returns the current
// path without modification.
-bool ConvertToLongPath(const std::wstring& short_path, std::wstring* long_path);
+bool ConvertToLongPath(const string16& short_path, string16* long_path);
// Returns true if the current point is close enough to the origin point in
// space and time that it would be considered a double click.
@@ -149,15 +91,15 @@ bool IsWindowActive(HWND hwnd);
// Returns whether the specified file name is a reserved name on windows.
// This includes names like "com2.zip" (which correspond to devices) and
// desktop.ini and thumbs.db which have special meaning to the windows shell.
-bool IsReservedName(const std::wstring& filename);
+bool IsReservedName(const string16& filename);
// A wrapper around Windows' MessageBox function. Using a Chrome specific
// MessageBox function allows us to control certain RTL locale flags so that
// callers don't have to worry about adding these flags when running in a
// right-to-left locale.
int MessageBox(HWND hwnd,
- const std::wstring& text,
- const std::wstring& caption,
+ const string16& text,
+ const string16& caption,
UINT flags);
// Returns the system set window title font.
@@ -166,6 +108,7 @@ gfx::Font GetWindowTitleFont();
// The thickness of an auto-hide taskbar in pixels.
extern const int kAutoHideTaskbarThicknessPx;
-} // namespace win_util
+} // namespace win
+} // namespace app
-#endif // APP_WIN_UTIL_H_
+#endif // APP_WIN_WIN_UTIL_H_
diff --git a/app/win/win_util_unittest.cc b/app/win/win_util_unittest.cc
new file mode 100644
index 0000000..0dc4568
--- /dev/null
+++ b/app/win/win_util_unittest.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "app/win/win_util.h"
+#include "gfx/rect.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace app {
+namespace win {
+
+TEST(WinUtilTest, EnsureRectIsVisibleInRect) {
+ gfx::Rect parent_rect(0, 0, 500, 400);
+
+ {
+ // Child rect x < 0
+ gfx::Rect child_rect(-50, 20, 100, 100);
+ EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
+ EXPECT_EQ(gfx::Rect(10, 20, 100, 100), child_rect);
+ }
+
+ {
+ // Child rect y < 0
+ gfx::Rect child_rect(20, -50, 100, 100);
+ EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
+ EXPECT_EQ(gfx::Rect(20, 10, 100, 100), child_rect);
+ }
+
+ {
+ // Child rect right > parent_rect.right
+ gfx::Rect child_rect(450, 20, 100, 100);
+ EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
+ EXPECT_EQ(gfx::Rect(390, 20, 100, 100), child_rect);
+ }
+
+ {
+ // Child rect bottom > parent_rect.bottom
+ gfx::Rect child_rect(20, 350, 100, 100);
+ EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
+ EXPECT_EQ(gfx::Rect(20, 290, 100, 100), child_rect);
+ }
+
+ {
+ // Child rect width > parent_rect.width
+ gfx::Rect child_rect(20, 20, 700, 100);
+ EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
+ EXPECT_EQ(gfx::Rect(20, 20, 480, 100), child_rect);
+ }
+
+ {
+ // Child rect height > parent_rect.height
+ gfx::Rect child_rect(20, 20, 100, 700);
+ EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
+ EXPECT_EQ(gfx::Rect(20, 20, 100, 380), child_rect);
+ }
+}
+
+} // namespace win
+} // namespace app
diff --git a/app/win_util_path.cc b/app/win_util_path.cc
deleted file mode 100644
index 5717f4e..0000000
--- a/app/win_util_path.cc
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "app/win_util.h"
-
-namespace win_util {
-
-bool ConvertToLongPath(const std::wstring& short_path,
- std::wstring* long_path) {
- wchar_t long_path_buf[MAX_PATH];
- DWORD return_value = GetLongPathName(short_path.c_str(), long_path_buf,
- MAX_PATH);
- if (return_value != 0 && return_value < MAX_PATH) {
- *long_path = long_path_buf;
- return true;
- }
-
- return false;
-}
-
-} // namespace win_util
diff --git a/app/win_util_unittest.cc b/app/win_util_unittest.cc
deleted file mode 100644
index 2c0eafc..0000000
--- a/app/win_util_unittest.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "app/win_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-TEST(WinUtilTest, EnsureRectIsVisibleInRect) {
- gfx::Rect parent_rect(0, 0, 500, 400);
-
- {
- // Child rect x < 0
- gfx::Rect child_rect(-50, 20, 100, 100);
- win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(10, 20, 100, 100), child_rect);
- }
-
- {
- // Child rect y < 0
- gfx::Rect child_rect(20, -50, 100, 100);
- win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(20, 10, 100, 100), child_rect);
- }
-
- {
- // Child rect right > parent_rect.right
- gfx::Rect child_rect(450, 20, 100, 100);
- win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(390, 20, 100, 100), child_rect);
- }
-
- {
- // Child rect bottom > parent_rect.bottom
- gfx::Rect child_rect(20, 350, 100, 100);
- win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(20, 290, 100, 100), child_rect);
- }
-
- {
- // Child rect width > parent_rect.width
- gfx::Rect child_rect(20, 20, 700, 100);
- win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(20, 20, 480, 100), child_rect);
- }
-
- {
- // Child rect height > parent_rect.height
- gfx::Rect child_rect(20, 20, 100, 700);
- win_util::EnsureRectIsVisibleInRect(parent_rect, &child_rect, 10);
- EXPECT_EQ(gfx::Rect(20, 20, 100, 380), child_rect);
- }
-}
-
-static const struct filename_case {
- const wchar_t* filename;
- const wchar_t* filter_selected;
- const wchar_t* suggested_ext;
- const wchar_t* result;
-} filename_cases[] = {
- // Test a specific filter (*.jpg).
- {L"f", L"*.jpg", L"jpg", L"f.jpg"},
- {L"f.", L"*.jpg", L"jpg", L"f..jpg"},
- {L"f..", L"*.jpg", L"jpg", L"f...jpg"},
- {L"f.jpeg", L"*.jpg", L"jpg", L"f.jpeg"},
- // Further guarantees.
- {L"f.jpg.jpg", L"*.jpg", L"jpg", L"f.jpg.jpg"},
- {L"f.exe.jpg", L"*.jpg", L"jpg", L"f.exe.jpg"},
- {L"f.jpg.exe", L"*.jpg", L"jpg", L"f.jpg.exe.jpg"},
- {L"f.exe..", L"*.jpg", L"jpg", L"f.exe...jpg"},
- {L"f.jpg..", L"*.jpg", L"jpg", L"f.jpg...jpg"},
- // Test the All Files filter (*.jpg).
- {L"f", L"*.*", L"jpg", L"f"},
- {L"f.", L"*.*", L"jpg", L"f"},
- {L"f..", L"*.*", L"jpg", L"f"},
- {L"f.jpg", L"*.*", L"jpg", L"f.jpg"},
- {L"f.jpeg", L"*.*", L"jpg", L"f.jpeg"}, // Same MIME type (diff. ext).
- // Test the empty filter, which should behave identically to the
- // All Files filter.
- {L"f", L"", L"jpg", L"f"},
- {L"f.", L"", L"jpg", L"f"},
- {L"f..", L"", L"jpg", L"f"},
- {L"f.jpg", L"", L"jpg", L"f.jpg"},
- {L"f.jpeg", L"", L"jpg", L"f.jpeg"},
-};