Home | History | Annotate | Download | only in forms
      1 /*
      2  * Copyright (C) 2010 Google Inc. All rights reserved.
      3  * Copyright (C) 2011 Apple Inc. All rights reserved.
      4  * Copyright (C) 2012 Samsung Electronics. All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions are
      8  * met:
      9  *
     10  *     * Redistributions of source code must retain the above copyright
     11  * notice, this list of conditions and the following disclaimer.
     12  *     * Redistributions in binary form must reproduce the above
     13  * copyright notice, this list of conditions and the following disclaimer
     14  * in the documentation and/or other materials provided with the
     15  * distribution.
     16  *     * Neither the name of Google Inc. nor the names of its
     17  * contributors may be used to endorse or promote products derived from
     18  * this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #ifndef InputTypeView_h
     34 #define InputTypeView_h
     35 
     36 #include "core/page/FocusDirection.h"
     37 #include "wtf/FastAllocBase.h"
     38 #include "wtf/Forward.h"
     39 #include "wtf/Noncopyable.h"
     40 #include "wtf/RefCounted.h"
     41 #include "wtf/RefPtr.h"
     42 
     43 namespace WebCore {
     44 
     45 class BeforeTextInsertedEvent;
     46 class Element;
     47 class Event;
     48 class HTMLFormElement;
     49 class HTMLInputElement;
     50 class KeyboardEvent;
     51 class MouseEvent;
     52 class RenderObject;
     53 class RenderStyle;
     54 class TouchEvent;
     55 
     56 struct ClickHandlingState {
     57     WTF_MAKE_FAST_ALLOCATED;
     58 
     59 public:
     60     bool checked;
     61     bool indeterminate;
     62     RefPtr<HTMLInputElement> checkedRadioButton;
     63 };
     64 
     65 // An InputTypeView object represents the UI-specific part of an
     66 // HTMLInputElement. Do not expose instances of InputTypeView and classes
     67 // derived from it to classes other than HTMLInputElement.
     68 class InputTypeView : public RefCounted<InputTypeView> {
     69     WTF_MAKE_NONCOPYABLE(InputTypeView);
     70     WTF_MAKE_FAST_ALLOCATED;
     71 
     72 public:
     73     static PassRefPtr<InputTypeView> create(HTMLInputElement&);
     74     virtual ~InputTypeView();
     75 
     76     virtual bool sizeShouldIncludeDecoration(int defaultSize, int& preferredSize) const;
     77     virtual void handleClickEvent(MouseEvent*);
     78     virtual void handleMouseDownEvent(MouseEvent*);
     79     virtual PassOwnPtr<ClickHandlingState> willDispatchClick();
     80     virtual void didDispatchClick(Event*, const ClickHandlingState&);
     81     virtual void handleKeydownEvent(KeyboardEvent*);
     82     virtual void handleKeypressEvent(KeyboardEvent*);
     83     virtual void handleKeyupEvent(KeyboardEvent*);
     84     virtual void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*);
     85     virtual void handleTouchEvent(TouchEvent*);
     86     virtual void forwardEvent(Event*);
     87     virtual bool shouldSubmitImplicitly(Event*);
     88     virtual PassRefPtr<HTMLFormElement> formForSubmission() const;
     89     virtual bool hasCustomFocusLogic() const;
     90     virtual void handleFocusEvent(Element* oldFocusedElement, FocusDirection);
     91     virtual void handleBlurEvent();
     92     virtual void subtreeHasChanged();
     93     virtual bool hasTouchEventHandler() const;
     94     virtual void blur();
     95     virtual RenderObject* createRenderer(RenderStyle*) const;
     96     virtual PassRefPtr<RenderStyle> customStyleForRenderer(PassRefPtr<RenderStyle>);
     97     virtual void startResourceLoading();
     98     virtual void closePopupView();
     99     virtual void createShadowSubtree();
    100     virtual void destroyShadowSubtree();
    101     virtual void minOrMaxAttributeChanged();
    102     virtual void stepAttributeChanged();
    103     virtual void altAttributeChanged();
    104     virtual void srcAttributeChanged();
    105     virtual void updateView();
    106     virtual void attributeChanged();
    107     virtual void multipleAttributeChanged();
    108     virtual void disabledAttributeChanged();
    109     virtual void readonlyAttributeChanged();
    110     virtual void requiredAttributeChanged();
    111     virtual void valueAttributeChanged();
    112     virtual void listAttributeTargetChanged();
    113     virtual void updateClearButtonVisibility();
    114 
    115 protected:
    116     InputTypeView(HTMLInputElement& element) : m_element(element) { }
    117     HTMLInputElement& element() const { return m_element; }
    118 
    119 private:
    120     // Not a RefPtr because the HTMLInputElement object owns this InputTypeView
    121     // object.
    122     HTMLInputElement& m_element;
    123 };
    124 
    125 } // namespace WebCore
    126 #endif
    127