Home | History | Annotate | Download | only in platform
      1 /*
      2  * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "core/platform/ContextMenuItem.h"
     28 
     29 #include "core/platform/ContextMenu.h"
     30 
     31 namespace WebCore {
     32 
     33 ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu)
     34     : m_type(type)
     35     , m_action(action)
     36     , m_title(title)
     37     , m_enabled(true)
     38     , m_checked(false)
     39 {
     40     if (subMenu)
     41         setSubMenu(subMenu);
     42 }
     43 
     44 ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, bool enabled, bool checked)
     45     : m_type(type)
     46     , m_action(action)
     47     , m_title(title)
     48     , m_enabled(enabled)
     49     , m_checked(checked)
     50 {
     51 }
     52 
     53 ContextMenuItem::ContextMenuItem(ContextMenuAction action, const String& title, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems)
     54     : m_type(SubmenuType)
     55     , m_action(action)
     56     , m_title(title)
     57     , m_enabled(enabled)
     58     , m_checked(checked)
     59     , m_subMenuItems(subMenuItems)
     60 {
     61 }
     62 
     63 ContextMenuItem::~ContextMenuItem()
     64 {
     65 }
     66 
     67 void ContextMenuItem::setSubMenu(ContextMenu* subMenu)
     68 {
     69     if (subMenu) {
     70         m_type = SubmenuType;
     71         m_subMenuItems = subMenu->items();
     72     } else {
     73         m_type = ActionType;
     74         m_subMenuItems.clear();
     75     }
     76 }
     77 
     78 void ContextMenuItem::setType(ContextMenuItemType type)
     79 {
     80     m_type = type;
     81 }
     82 
     83 ContextMenuItemType ContextMenuItem::type() const
     84 {
     85     return m_type;
     86 }
     87 
     88 void ContextMenuItem::setAction(ContextMenuAction action)
     89 {
     90     m_action = action;
     91 }
     92 
     93 ContextMenuAction ContextMenuItem::action() const
     94 {
     95     return m_action;
     96 }
     97 
     98 void ContextMenuItem::setChecked(bool checked)
     99 {
    100     m_checked = checked;
    101 }
    102 
    103 bool ContextMenuItem::checked() const
    104 {
    105     return m_checked;
    106 }
    107 
    108 void ContextMenuItem::setEnabled(bool enabled)
    109 {
    110     m_enabled = enabled;
    111 }
    112 
    113 bool ContextMenuItem::enabled() const
    114 {
    115     return m_enabled;
    116 }
    117 
    118 } // namespace WebCore
    119