1/* 2 * Copyright (C) 2006 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef ContextMenu_h 27#define ContextMenu_h 28 29#if ENABLE(CONTEXT_MENUS) 30 31#include <wtf/Noncopyable.h> 32 33#include "ContextMenuItem.h" 34#include "PlatformMenuDescription.h" 35#include <wtf/text/WTFString.h> 36 37#if PLATFORM(COCOA) 38#include <wtf/RetainPtr.h> 39#elif PLATFORM(WIN) 40#include <windows.h> 41#endif 42 43namespace WebCore { 44 45 class ContextMenuController; 46 47 class ContextMenu { 48 WTF_MAKE_NONCOPYABLE(ContextMenu); WTF_MAKE_FAST_ALLOCATED; 49 public: 50 ContextMenu(); 51 52 ContextMenuItem* itemWithAction(unsigned); 53 54#if USE(CROSS_PLATFORM_CONTEXT_MENUS) 55 explicit ContextMenu(PlatformContextMenu); 56 57 PlatformContextMenu platformContextMenu() const; 58 59 static PlatformContextMenu createPlatformContextMenuFromItems(const Vector<ContextMenuItem>&); 60 static void getContextMenuItems(PlatformContextMenu, Vector<ContextMenuItem>&); 61 62 // FIXME: When more platforms switch over, this should return const ContextMenuItem*'s. 63 ContextMenuItem* itemAtIndex(unsigned index) { return &m_items[index]; } 64 65 void setItems(const Vector<ContextMenuItem>& items) { m_items = items; } 66 const Vector<ContextMenuItem>& items() const { return m_items; } 67 68 void appendItem(const ContextMenuItem& item) { m_items.append(item); } 69#else 70 explicit ContextMenu(const PlatformMenuDescription); 71 ~ContextMenu(); 72 73 void insertItem(unsigned position, ContextMenuItem&); 74 void appendItem(ContextMenuItem&); 75 76 ContextMenuItem* itemAtIndex(unsigned, const PlatformMenuDescription); 77 78 unsigned itemCount() const; 79 80 PlatformMenuDescription platformDescription() const; 81 void setPlatformDescription(PlatformMenuDescription); 82 83 PlatformMenuDescription releasePlatformDescription(); 84#endif // USE(CROSS_PLATFORM_CONTEXT_MENUS) 85 86 private: 87#if USE(CROSS_PLATFORM_CONTEXT_MENUS) 88 Vector<ContextMenuItem> m_items; 89#else 90#if PLATFORM(COCOA) 91 // Keep this in sync with the PlatformMenuDescription typedef 92 RetainPtr<NSMutableArray> m_platformDescription; 93#else 94 PlatformMenuDescription m_platformDescription; 95#if OS(WINCE) 96 unsigned m_itemCount; 97#endif 98#endif 99 100#endif // USE(CROSS_PLATFORM_CONTEXT_MENUS) 101 }; 102 103#if !USE(CROSS_PLATFORM_CONTEXT_MENUS) 104Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription); 105PlatformMenuDescription platformMenuDescription(Vector<ContextMenuItem>&); 106#endif 107 108} 109 110#endif // ENABLE(CONTEXT_MENUS) 111#endif // ContextMenu_h 112