ContextMenu.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2006 Apple Computer, 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 COMPUTER, 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 COMPUTER, 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. #ifndef ContextMenu_h
  26. #define ContextMenu_h
  27. #if ENABLE(CONTEXT_MENUS)
  28. #include <wtf/Noncopyable.h>
  29. #include "ContextMenuItem.h"
  30. #include "PlatformMenuDescription.h"
  31. #include <wtf/text/WTFString.h>
  32. #if PLATFORM(MAC)
  33. #include <wtf/RetainPtr.h>
  34. #elif PLATFORM(WIN)
  35. #include <windows.h>
  36. #endif
  37. namespace WebCore {
  38. class ContextMenuController;
  39. class ContextMenu {
  40. WTF_MAKE_NONCOPYABLE(ContextMenu); WTF_MAKE_FAST_ALLOCATED;
  41. public:
  42. ContextMenu();
  43. ContextMenuItem* itemWithAction(unsigned);
  44. #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
  45. explicit ContextMenu(PlatformContextMenu);
  46. PlatformContextMenu platformContextMenu() const;
  47. static PlatformContextMenu createPlatformContextMenuFromItems(const Vector<ContextMenuItem>&);
  48. static void getContextMenuItems(PlatformContextMenu, Vector<ContextMenuItem>&);
  49. // FIXME: When more platforms switch over, this should return const ContextMenuItem*'s.
  50. ContextMenuItem* itemAtIndex(unsigned index) { return &m_items[index]; }
  51. void setItems(const Vector<ContextMenuItem>& items) { m_items = items; }
  52. const Vector<ContextMenuItem>& items() const { return m_items; }
  53. void appendItem(const ContextMenuItem& item) { m_items.append(item); }
  54. #else
  55. explicit ContextMenu(const PlatformMenuDescription);
  56. ~ContextMenu();
  57. void insertItem(unsigned position, ContextMenuItem&);
  58. void appendItem(ContextMenuItem&);
  59. ContextMenuItem* itemAtIndex(unsigned, const PlatformMenuDescription);
  60. unsigned itemCount() const;
  61. PlatformMenuDescription platformDescription() const;
  62. void setPlatformDescription(PlatformMenuDescription);
  63. PlatformMenuDescription releasePlatformDescription();
  64. #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
  65. private:
  66. #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
  67. Vector<ContextMenuItem> m_items;
  68. #else
  69. #if PLATFORM(MAC)
  70. // Keep this in sync with the PlatformMenuDescription typedef
  71. RetainPtr<NSMutableArray> m_platformDescription;
  72. #else
  73. PlatformMenuDescription m_platformDescription;
  74. #if OS(WINCE)
  75. unsigned m_itemCount;
  76. #endif
  77. #endif
  78. #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
  79. };
  80. #if !USE(CROSS_PLATFORM_CONTEXT_MENUS)
  81. Vector<ContextMenuItem> contextMenuItemVector(PlatformMenuDescription);
  82. PlatformMenuDescription platformMenuDescription(Vector<ContextMenuItem>&);
  83. #endif
  84. }
  85. #endif // ENABLE(CONTEXT_MENUS)
  86. #endif // ContextMenu_h