Codebase list mozc / 0d90165
Remove unnecessary API calls of GetProdAddress Since we no longer support Windows XP, it no longer makes sense to use GetProdAddress to use APIs that are guaranteed to be available on Windows Vista and later. BUG=#277 TEST= REF_BUG=18957181,27053168 REF_CL=114056348 REF_TIME=2016-02-07T06:31:07-08:00 REF_TIME_RAW=1454855467 -0800 Yohei Yukawa 8 years ago
4 changed file(s) with 42 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
444444
445445 nt_path->clear();
446446
447 typedef DWORD (WINAPI *GetFinalPathNameByHandleWFunc)(
448 __in HANDLE file,
449 __out wchar_t *buffer,
450 __in DWORD buffer_num_chars,
451 __in DWORD flags);
452 GetFinalPathNameByHandleWFunc get_final_path_name_by_handle =
453 reinterpret_cast<GetFinalPathNameByHandleWFunc>(
454 ::GetProcAddress(WinUtil::GetSystemModuleHandle(L"kernel32.dll"),
455 "GetFinalPathNameByHandleW"));
456 if (get_final_path_name_by_handle == nullptr) {
457 return false;
458 }
459
460447 ScopedHandle file_handle(::CreateFileW(
461448 dos_path.c_str(), 0,
462449 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
471458 const size_t kMaxPath = 4096;
472459 unique_ptr<wchar_t[]> ntpath_buffer(
473460 new wchar_t[kMaxPath]);
474 const DWORD copied_len_without_null = get_final_path_name_by_handle(
461 const DWORD copied_len_without_null = ::GetFinalPathNameByHandleW(
475462 file_handle.get(),
476463 ntpath_buffer.get(),
477464 kMaxPath,
00 MAJOR=2
11 MINOR=17
2 BUILD=2451
2 BUILD=2452
33 REVISION=102
44 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
55 # downloaded by NaCl Mozc.
320320 if (FAILED(hr)) {
321321 return nullptr;
322322 }
323 const auto kernel32 = WinUtil::GetSystemModuleHandle(L"kernel32.dll");
324 const auto get_user_default_locale_name =
325 reinterpret_cast<GetUserDefaultLocaleNamePtr>(
326 ::GetProcAddress(kernel32, "GetUserDefaultLocaleName"));
327 if (get_user_default_locale_name == nullptr) {
328 return nullptr;
329 }
330 return new DirectWriteTextRenderer(
331 d2d_factory, dwrite_factory, interop, get_user_default_locale_name);
323 return new DirectWriteTextRenderer(d2d_factory, dwrite_factory, interop);
332324 }
333325 virtual ~DirectWriteTextRenderer() {
334326 }
335327
336328 private:
337 typedef int (WINAPI *GetUserDefaultLocaleNamePtr)(LPWSTR locale_name,
338 int locale_name_buffer_len);
339
340329 typedef HRESULT (WINAPI *D2D1CreateFactoryPtr)(
341330 D2D1_FACTORY_TYPE factory_type,
342331 const IID &iid,
351340 DirectWriteTextRenderer(
352341 ID2D1Factory *d2d2_factory,
353342 IDWriteFactory *dwrite_factory,
354 IDWriteGdiInterop *dwrite_interop,
355 GetUserDefaultLocaleNamePtr get_user_default_locale_name)
343 IDWriteGdiInterop *dwrite_interop)
356344 : d2d2_factory_(d2d2_factory),
357345 dwrite_factory_(dwrite_factory),
358 dwrite_interop_(dwrite_interop),
359 get_user_default_locale_name_(get_user_default_locale_name) {
346 dwrite_interop_(dwrite_interop) {
360347 OnThemeChanged();
361348 }
362349
529516 }
530517
531518 wchar_t locale_name[LOCALE_NAME_MAX_LENGTH] = {};
532 if (get_user_default_locale_name_(locale_name, arraysize(locale_name))
519 if (::GetUserDefaultLocaleName(locale_name, arraysize(locale_name))
533520 == 0) {
534521 return nullptr;
535522 }
572559 mutable CComPtr<ID2D1DCRenderTarget> dc_render_target_;
573560 CComPtr<IDWriteGdiInterop> dwrite_interop_;
574561 vector<RenderInfo> render_info_;
575 GetUserDefaultLocaleNamePtr get_user_default_locale_name_;
576562
577563 DISALLOW_COPY_AND_ASSIGN(DirectWriteTextRenderer);
578564 };
3434 #include <atlapp.h>
3535 #include <atlgdi.h>
3636 #include <atlmisc.h>
37 #include <winuser.h>
3738
3839 #include <algorithm>
3940 #include <limits>
4243 #include <vector>
4344
4445 #include "base/logging.h"
46 #include "base/system_util.h"
4547 #include "base/util.h"
4648 #include "base/win_util.h"
4749 #include "protocol/renderer_command.pb.h"
660662 class NativeWindowPositionAPI : public WindowPositionInterface {
661663 public:
662664 NativeWindowPositionAPI()
663 : logical_to_physical_point_(GetLogicalToPhysicalPoint()) {
665 : logical_to_physical_point_for_per_monitor_dpi_(
666 GetLogicalToPhysicalPointForPerMonitorDPI()) {
664667 }
665668
666669 virtual ~NativeWindowPositionAPI() {}
675678 if (!::IsWindow(window_handle)) {
676679 return false;
677680 }
678 if (logical_to_physical_point_ == NULL) {
679 // In Windows XP, LogicalToPhysicalPoint API is not available.
680 // In this case, we simply returns the specified coordinate and returns
681 // true.
682 *physical_coordinate = logical_coordinate;
683 return true;
684 }
681
685682 // The attached window is likely to be a child window but only root
686683 // windows are fully supported by LogicalToPhysicalPoint API. Using
687684 // root window handle instead of target window handle is likely to make
699696 // coordinates to a DPI-aware process and convert them to physical screen
700697 // coordinates by LogicalToPhysicalPoint API.
701698 *physical_coordinate = logical_coordinate;
702 return logical_to_physical_point_(root_window_handle,
703 physical_coordinate) != FALSE;
699
700 // Despite its name, LogicalToPhysicalPoint API no longer converts
701 // coordinates on Windows 8.1 and later. We must use
702 // LogicalToPhysicalPointForPerMonitorDPI API instead when it is available.
703 // See http://go.microsoft.com/fwlink/?LinkID=307061
704 if (SystemUtil::IsWindows8_1OrLater()) {
705 if (logical_to_physical_point_for_per_monitor_dpi_ == nullptr) {
706 return false;
707 }
708 return logical_to_physical_point_for_per_monitor_dpi_(
709 root_window_handle, physical_coordinate) != FALSE;
710 }
711 // On Windows 8 and prior, it's OK to rely on LogicalToPhysicalPoint API.
712 return ::LogicalToPhysicalPoint(
713 root_window_handle, physical_coordinate) != FALSE;
704714 }
705715
706716 // This method is not const to implement Win32WindowInterface.
748758 }
749759
750760 private:
751 typedef BOOL (WINAPI *FPLogicalToPhysicalPoint)(HWND window_handle,
752 POINT *point);
753 static FPLogicalToPhysicalPoint GetLogicalToPhysicalPoint() {
754 // LogicalToPhysicalPoint API is available in Vista or later.
761 typedef BOOL (WINAPI *LogicalToPhysicalPointForPerMonitorDPIFunc)(
762 HWND window_handle, POINT *point);
763 static LogicalToPhysicalPointForPerMonitorDPIFunc
764 GetLogicalToPhysicalPointForPerMonitorDPI() {
765 // LogicalToPhysicalPointForPerMonitorDPI API is available on Windows 8.1
766 // and later.
767 if (!SystemUtil::IsWindows8_1OrLater()) {
768 return nullptr;
769 }
770
755771 const HMODULE module = WinUtil::GetSystemModuleHandle(L"user32.dll");
756772 if (module == nullptr) {
757773 return nullptr;
758774 }
759 // Despite its name, LogicalToPhysicalPoint API no longer converts
760 // coordinates on Windows 8.1 and later. We must use
761 // LogicalToPhysicalPointForPerMonitorDPI API instead when it is available.
762 // See http://go.microsoft.com/fwlink/?LinkID=307061
763 void *function = ::GetProcAddress(
764 module, "LogicalToPhysicalPointForPerMonitorDPI");
765 if (function == nullptr) {
766 // When LogicalToPhysicalPointForPerMonitorDPI API does not exist but
767 // LogicalToPhysicalPoint API exists, LogicalToPhysicalPoint works fine.
768 // This is the case on Windows Vista, Windows 7 and Windows 8.
769 function = ::GetProcAddress(module, "LogicalToPhysicalPoint");
770 if (function == nullptr) {
771 return nullptr;
772 }
773 }
774 return reinterpret_cast<FPLogicalToPhysicalPoint>(function);
775 }
776
777 FPLogicalToPhysicalPoint logical_to_physical_point_;
775 return reinterpret_cast<LogicalToPhysicalPointForPerMonitorDPIFunc>(
776 ::GetProcAddress(module, "LogicalToPhysicalPointForPerMonitorDPI"));
777 }
778
779 const LogicalToPhysicalPointForPerMonitorDPIFunc
780 logical_to_physical_point_for_per_monitor_dpi_;
778781
779782 DISALLOW_COPY_AND_ASSIGN(NativeWindowPositionAPI);
780783 };