diff options
Diffstat (limited to 'WebCore/platform/win')
-rw-r--r-- | WebCore/platform/win/ContextMenuItemWin.cpp | 212 | ||||
-rw-r--r-- | WebCore/platform/win/ContextMenuWin.cpp | 196 | ||||
-rw-r--r-- | WebCore/platform/win/FileSystemWin.cpp | 5 |
3 files changed, 81 insertions, 332 deletions
diff --git a/WebCore/platform/win/ContextMenuItemWin.cpp b/WebCore/platform/win/ContextMenuItemWin.cpp index 8d1c175..59aedcd 100644 --- a/WebCore/platform/win/ContextMenuItemWin.cpp +++ b/WebCore/platform/win/ContextMenuItemWin.cpp @@ -28,198 +28,66 @@ #include "ContextMenu.h" -#include <wtf/text/CString.h> -#include <windows.h> - -#if OS(WINCE) -#ifndef MFS_DISABLED -#define MFS_DISABLED MF_GRAYED -#endif -#ifndef MIIM_FTYPE -#define MIIM_FTYPE MIIM_TYPE -#endif -#ifndef MIIM_STRING -#define MIIM_STRING 0 -#endif -#endif - namespace WebCore { -ContextMenuItem::ContextMenuItem(LPMENUITEMINFO item) - : m_platformDescription(item) -{ -} - -ContextMenuItem::ContextMenuItem(ContextMenu* subMenu) +ContextMenuItem::ContextMenuItem(const MENUITEMINFO& info) { - m_platformDescription = (LPMENUITEMINFO)malloc(sizeof(MENUITEMINFO)); - if (!m_platformDescription) - return; + if (info.fMask & MIIM_FTYPE) + m_type = info.fType == MFT_SEPARATOR ? SeparatorType : ActionType; + else + m_type = SeparatorType; - memset(m_platformDescription, 0, sizeof(MENUITEMINFO)); - m_platformDescription->cbSize = sizeof(MENUITEMINFO); + if (m_type == ActionType && info.fMask & MIIM_STRING) + m_title = String(info.dwTypeData, info.cch); - m_platformDescription->wID = ContextMenuItemTagNoAction; - if (subMenu) { - m_platformDescription->fMask |= MIIM_SUBMENU; - m_platformDescription->hSubMenu = subMenu->platformDescription(); + if ((info.fMask & MIIM_SUBMENU) && info.hSubMenu) { + m_type = SubmenuType; + ContextMenu::getContextMenuItems(info.hSubMenu, m_subMenuItems); } -} - -ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu) -{ - m_platformDescription = (LPMENUITEMINFO)malloc(sizeof(MENUITEMINFO)); - if (!m_platformDescription) - return; - memset(m_platformDescription, 0, sizeof(MENUITEMINFO)); - m_platformDescription->cbSize = sizeof(MENUITEMINFO); - m_platformDescription->fMask = MIIM_FTYPE; + if (info.fMask & MIIM_ID) + m_action = static_cast<ContextMenuAction>(info.wID); + else + m_action = ContextMenuItemTagNoAction; - if (type == SeparatorType) { - m_platformDescription->fType = MFT_SEPARATOR; - return; + if (info.fMask & MIIM_STATE) { + m_checked = info.fState & MFS_CHECKED; + m_enabled = !(info.fState & MFS_DISABLED); + } else { + m_checked = false; + m_enabled = false; } - - if (subMenu) { - m_platformDescription->fMask |= MIIM_STRING | MIIM_SUBMENU; - m_platformDescription->hSubMenu = subMenu->platformDescription(); - } else - m_platformDescription->fMask |= MIIM_STRING | MIIM_ID; - - m_platformDescription->fType = MFT_STRING; - m_platformDescription->wID = action; - - String t = title; - m_platformDescription->cch = t.length(); - m_platformDescription->dwTypeData = wcsdup(t.charactersWithNullTermination()); } -ContextMenuItem::ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool, bool) +// ContextMenuItem::nativeMenuItem doesn't set the info.dwTypeData. This is +// done to make the lifetime handling of the returned MENUITEMINFO easier on +// callers. Callers can set dwTypeData themselves (and make their own decisions +// about its lifetime) if they need it. +MENUITEMINFO ContextMenuItem::nativeMenuItem() const { - // FIXME: Implement -} + MENUITEMINFO info = {0}; + info.cbSize = sizeof(MENUITEMINFO); -ContextMenuItem::ContextMenuItem(ContextMenuAction, const String&, bool, bool, Vector<ContextMenuItem>&) -{ - // FIXME: Implement -} - -ContextMenuItem::~ContextMenuItem() -{ - if (m_platformDescription) { - if (m_platformDescription->fType == MFT_STRING) - free(m_platformDescription->dwTypeData); - free(m_platformDescription); + if (m_type == SeparatorType) { + info.fMask = MIIM_FTYPE; + info.fType = MFT_SEPARATOR; + return info; } -} - -LPMENUITEMINFO ContextMenuItem::releasePlatformDescription() -{ - LPMENUITEMINFO info = m_platformDescription; - m_platformDescription = 0; - return info; -} - -ContextMenuItemType ContextMenuItem::type() const -{ - ContextMenuItemType type = ActionType; - if (((m_platformDescription->fType & ~MFT_OWNERDRAW) == MFT_STRING) && m_platformDescription->hSubMenu) - type = SubmenuType; - else if (m_platformDescription->fType & MFT_SEPARATOR) - type = SeparatorType; - - return type; -} - -ContextMenuAction ContextMenuItem::action() const -{ - return static_cast<ContextMenuAction>(m_platformDescription->wID); -} - -String ContextMenuItem::title() const -{ - return String(m_platformDescription->dwTypeData, wcslen(m_platformDescription->dwTypeData)); -} - -PlatformMenuDescription ContextMenuItem::platformSubMenu() const -{ - return m_platformDescription->hSubMenu; -} - -void ContextMenuItem::setType(ContextMenuItemType type) -{ - if (type == SeparatorType) - m_platformDescription->fType = MFT_SEPARATOR; - else - m_platformDescription->fType = MFT_STRING; -} - -void ContextMenuItem::setAction(ContextMenuAction action) -{ - m_platformDescription->wID = action; -} - -void ContextMenuItem::setTitle(const String& title) -{ - if (m_platformDescription->dwTypeData) - free(m_platformDescription->dwTypeData); - - m_platformDescription->cch = title.length(); - String titleCopy = title; - m_platformDescription->dwTypeData = wcsdup(titleCopy.charactersWithNullTermination()); -} - -void ContextMenuItem::setSubMenu(ContextMenu* subMenu) -{ - if (subMenu->platformDescription() == m_platformDescription->hSubMenu) - return; - - if (m_platformDescription->hSubMenu) - ::DestroyMenu(m_platformDescription->hSubMenu); - m_platformDescription->fMask |= MIIM_SUBMENU; - m_platformDescription->hSubMenu = subMenu->releasePlatformDescription(); -} + info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STATE; + info.fType = MFT_STRING; -void ContextMenuItem::setSubMenu(Vector<ContextMenuItem>&) -{ - // FIXME: Implement -} + info.wID = m_action; -void ContextMenuItem::setChecked(bool checked) -{ - m_platformDescription->fMask |= MIIM_STATE; - if (checked) { - m_platformDescription->fState &= ~MFS_UNCHECKED; - m_platformDescription->fState |= MFS_CHECKED; - } else { - m_platformDescription->fState &= ~MFS_CHECKED; - m_platformDescription->fState |= MFS_UNCHECKED; + if (m_type == SubmenuType) { + info.fMask |= MIIM_SUBMENU; + info.hSubMenu = ContextMenu::createNativeMenuFromItems(m_subMenuItems); } -} -bool ContextMenuItem::checked() const -{ - // FIXME - Implement - return false; -} + info.fState |= m_enabled ? MFS_ENABLED : MFS_DISABLED; + info.fState |= m_checked ? MFS_CHECKED : MFS_UNCHECKED; -void ContextMenuItem::setEnabled(bool enabled) -{ - m_platformDescription->fMask |= MIIM_STATE; - if (enabled) { - m_platformDescription->fState &= ~MFS_DISABLED; - m_platformDescription->fState |= MFS_ENABLED; - } else { - m_platformDescription->fState &= ~MFS_ENABLED; - m_platformDescription->fState |= MFS_DISABLED; - } -} - -bool ContextMenuItem::enabled() const -{ - return !(m_platformDescription->fState & MFS_DISABLED); + return info; } } diff --git a/WebCore/platform/win/ContextMenuWin.cpp b/WebCore/platform/win/ContextMenuWin.cpp index 10443aa..24c355d 100644 --- a/WebCore/platform/win/ContextMenuWin.cpp +++ b/WebCore/platform/win/ContextMenuWin.cpp @@ -32,6 +32,7 @@ #include "Node.h" #include <tchar.h> #include <windows.h> +#include <wtf/Vector.h> #include <wtf/text/CString.h> #ifndef MIIM_FTYPE @@ -43,184 +44,67 @@ namespace WebCore { -ContextMenu::ContextMenu(const HitTestResult& result) - : m_hitTestResult(result) - , m_platformDescription(0) -#if OS(WINCE) - , m_itemCount(0) -#endif +ContextMenu::ContextMenu(HMENU menu) { - setPlatformDescription(::CreatePopupMenu()); -} - -ContextMenu::ContextMenu(const HitTestResult& result, const PlatformMenuDescription menu) - : m_hitTestResult(result) - , m_platformDescription(0) -#if OS(WINCE) - , m_itemCount(0) -#endif -{ - setPlatformDescription(menu); -} - -ContextMenu::~ContextMenu() -{ - if (m_platformDescription) - ::DestroyMenu(m_platformDescription); -} - -unsigned ContextMenu::itemCount() const -{ -#if OS(WINCE) - return m_itemCount; -#else - if (!m_platformDescription) - return 0; - - return ::GetMenuItemCount(m_platformDescription); -#endif + getContextMenuItems(menu, m_items); } -#if OS(WINCE) -static bool insertMenuItem(PlatformMenuDescription menu, unsigned int position, ContextMenuItem& item) +void ContextMenu::getContextMenuItems(HMENU menu, Vector<ContextMenuItem>& items) { - UINT flags = MF_BYPOSITION; - UINT newItem = 0; - LPCWSTR title = 0; - - if (item.type() == SeparatorType) - flags |= MF_SEPARATOR; - else { - flags |= MF_STRING; - flags |= item.checked() ? MF_CHECKED : MF_UNCHECKED; - flags |= item.enabled() ? MF_ENABLED : MF_GRAYED; - - PlatformMenuItemDescription description = item.releasePlatformDescription(); - title = description->dwTypeData; - description->dwTypeData = 0; - - if (description->hSubMenu) { - flags |= MF_POPUP; - newItem = reinterpret_cast<UINT>(description->hSubMenu); - description->hSubMenu = 0; - } else - newItem = description->wID; - - free(description); - } - - return ::InsertMenuW(menu, position, flags, newItem, title); -} -#endif - -void ContextMenu::insertItem(unsigned int position, ContextMenuItem& item) -{ - if (!m_platformDescription) + int count = ::GetMenuItemCount(menu); + if (count <= 0) return; - checkOrEnableIfNeeded(item); + for (int i = 0; i < count; ++i) { + MENUITEMINFO info = {0}; + info.cbSize = sizeof(MENUITEMINFO); + info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE | MIIM_SUBMENU; -#if OS(WINCE) - if (insertMenuItem(m_platformDescription, position, item)) - ++m_itemCount; -#else - ::InsertMenuItem(m_platformDescription, position, TRUE, item.releasePlatformDescription()); -#endif -} - -void ContextMenu::appendItem(ContextMenuItem& item) -{ - insertItem(itemCount(), item); -} + if (!::GetMenuItemInfo(menu, i, TRUE, &info)) + continue; -static ContextMenuItem* contextMenuItemByIdOrPosition(HMENU menu, unsigned id, BOOL byPosition) -{ - if (!menu) - return 0; - LPMENUITEMINFO info = static_cast<LPMENUITEMINFO>(malloc(sizeof(MENUITEMINFO))); - if (!info) - return 0; - - memset(info, 0, sizeof(MENUITEMINFO)); - - info->cbSize = sizeof(MENUITEMINFO); - - // Setting MIIM_DATA which is useful for WebKit clients who store data in this member for their custom menu items. - info->fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_DATA; - - if (!::GetMenuItemInfo(menu, id, byPosition, info)) { - free(info); - return 0; - } - - if (info->fType & MFT_STRING) { - LPTSTR buffer = static_cast<LPTSTR>(malloc(++info->cch * sizeof(TCHAR))); - if (!buffer) { - free(info); - return 0; + if (info.fType == MFT_SEPARATOR) { + items.append(ContextMenuItem(SeparatorType, ContextMenuItemTagNoAction, String())); + continue; } - info->dwTypeData = buffer; - ::GetMenuItemInfo(menu, id, byPosition, info); - } - - return new ContextMenuItem(info); -} -ContextMenuItem* ContextMenu::itemWithAction(unsigned action) -{ - return contextMenuItemByIdOrPosition(m_platformDescription, action, FALSE); -} + int menuStringLength = info.cch + 1; + OwnArrayPtr<WCHAR> menuString(new WCHAR[menuStringLength]); + info.dwTypeData = menuString.get(); + info.cch = menuStringLength; -ContextMenuItem* ContextMenu::itemAtIndex(unsigned index, const PlatformMenuDescription platformDescription) -{ - return contextMenuItemByIdOrPosition(platformDescription, index, TRUE); + if (::GetMenuItemInfo(menu, i, TRUE, &info)) + items.append(ContextMenuItem(info)); + } } -void ContextMenu::setPlatformDescription(HMENU menu) +HMENU ContextMenu::createNativeMenuFromItems(const Vector<ContextMenuItem>& items) { - if (menu == m_platformDescription) - return; - - if (m_platformDescription) - ::DestroyMenu(m_platformDescription); + HMENU menu = ::CreatePopupMenu(); - m_platformDescription = menu; - if (!m_platformDescription) - return; + for (size_t i = 0; i < items.size(); ++i) { + const ContextMenuItem& item = items[i]; -#if !OS(WINCE) - MENUINFO menuInfo = {0}; - menuInfo.cbSize = sizeof(MENUINFO); - menuInfo.fMask = MIM_STYLE; - ::GetMenuInfo(m_platformDescription, &menuInfo); - menuInfo.fMask = MIM_STYLE; - menuInfo.dwStyle |= MNS_NOTIFYBYPOS; - ::SetMenuInfo(m_platformDescription, &menuInfo); -#endif -} + MENUITEMINFO menuItem = item.nativeMenuItem(); -HMENU ContextMenu::platformDescription() const -{ - return m_platformDescription; -} + // ContextMenuItem::nativeMenuItem doesn't set the title of the MENUITEMINFO to make the + // lifetime handling easier for callers. + String itemTitle = item.title(); + if (item.type() != SeparatorType) { + menuItem.fMask |= MIIM_STRING; + menuItem.cch = itemTitle.length(); + menuItem.dwTypeData = const_cast<LPWSTR>(itemTitle.charactersWithNullTermination()); + } -HMENU ContextMenu::releasePlatformDescription() -{ - HMENU description = m_platformDescription; - m_platformDescription = 0; - return description; -} + ::InsertMenuItem(menu, i, TRUE, &menuItem); + } -Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription) -{ - // FIXME - Implement - return Vector<ContextMenuItem>(); + return menu; } -PlatformMenuDescription platformMenuDescription(Vector<ContextMenuItem>& menuItemVector) +HMENU ContextMenu::nativeMenu() const { - // FIXME - Implement - return 0; + return createNativeMenuFromItems(m_items); } } // namespace WebCore diff --git a/WebCore/platform/win/FileSystemWin.cpp b/WebCore/platform/win/FileSystemWin.cpp index cef7196..5ee3b8e 100644 --- a/WebCore/platform/win/FileSystemWin.cpp +++ b/WebCore/platform/win/FileSystemWin.cpp @@ -134,10 +134,7 @@ String pathGetFileName(const String& path) String directoryName(const String& path) { - String fileName = pathGetFileName(path); - String dirName = String(path); - dirName.truncate(dirName.length() - pathGetFileName(path).length()); - return dirName; + return path.left(path.length() - pathGetFileName(path).length()); } static String bundleName() |