1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/forms/nsFileControlFrame.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,157 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsFileControlFrame_h___ 1.10 +#define nsFileControlFrame_h___ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include "nsBlockFrame.h" 1.14 +#include "nsIFormControlFrame.h" 1.15 +#include "nsIDOMEventListener.h" 1.16 +#include "nsIAnonymousContentCreator.h" 1.17 +#include "nsCOMPtr.h" 1.18 + 1.19 +class nsTextControlFrame; 1.20 +class nsIDOMDragEvent; 1.21 + 1.22 +class nsFileControlFrame : public nsBlockFrame, 1.23 + public nsIFormControlFrame, 1.24 + public nsIAnonymousContentCreator 1.25 +{ 1.26 +public: 1.27 + nsFileControlFrame(nsStyleContext* aContext); 1.28 + 1.29 + virtual void Init(nsIContent* aContent, 1.30 + nsIFrame* aParent, 1.31 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.32 + 1.33 + virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, 1.34 + const nsRect& aDirtyRect, 1.35 + const nsDisplayListSet& aLists) MOZ_OVERRIDE; 1.36 + 1.37 + NS_DECL_QUERYFRAME 1.38 + NS_DECL_FRAMEARENA_HELPERS 1.39 + 1.40 + // nsIFormControlFrame 1.41 + virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) MOZ_OVERRIDE; 1.42 + virtual void SetFocus(bool aOn, bool aRepaint) MOZ_OVERRIDE; 1.43 + 1.44 + virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; 1.45 + 1.46 + virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; 1.47 + 1.48 +#ifdef DEBUG_FRAME_DUMP 1.49 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; 1.50 +#endif 1.51 + 1.52 + virtual nsresult AttributeChanged(int32_t aNameSpaceID, 1.53 + nsIAtom* aAttribute, 1.54 + int32_t aModType) MOZ_OVERRIDE; 1.55 + virtual void ContentStatesChanged(mozilla::EventStates aStates) MOZ_OVERRIDE; 1.56 + virtual bool IsLeaf() const MOZ_OVERRIDE 1.57 + { 1.58 + return true; 1.59 + } 1.60 + 1.61 + // nsIAnonymousContentCreator 1.62 + virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE; 1.63 + virtual void AppendAnonymousContentTo(nsBaseContentList& aElements, 1.64 + uint32_t aFilter) MOZ_OVERRIDE; 1.65 + 1.66 +#ifdef ACCESSIBILITY 1.67 + virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; 1.68 +#endif 1.69 + 1.70 + typedef bool (*AcceptAttrCallback)(const nsAString&, void*); 1.71 + 1.72 +protected: 1.73 + 1.74 + class MouseListener; 1.75 + friend class MouseListener; 1.76 + class MouseListener : public nsIDOMEventListener { 1.77 + public: 1.78 + NS_DECL_ISUPPORTS 1.79 + 1.80 + MouseListener(nsFileControlFrame* aFrame) 1.81 + : mFrame(aFrame) 1.82 + {} 1.83 + virtual ~MouseListener() {} 1.84 + 1.85 + void ForgetFrame() { 1.86 + mFrame = nullptr; 1.87 + } 1.88 + 1.89 + protected: 1.90 + nsFileControlFrame* mFrame; 1.91 + }; 1.92 + 1.93 + class SyncDisabledStateEvent; 1.94 + friend class SyncDisabledStateEvent; 1.95 + class SyncDisabledStateEvent : public nsRunnable 1.96 + { 1.97 + public: 1.98 + SyncDisabledStateEvent(nsFileControlFrame* aFrame) 1.99 + : mFrame(aFrame) 1.100 + {} 1.101 + 1.102 + NS_IMETHOD Run() MOZ_OVERRIDE { 1.103 + nsFileControlFrame* frame = static_cast<nsFileControlFrame*>(mFrame.GetFrame()); 1.104 + NS_ENSURE_STATE(frame); 1.105 + 1.106 + frame->SyncDisabledState(); 1.107 + return NS_OK; 1.108 + } 1.109 + 1.110 + private: 1.111 + nsWeakFrame mFrame; 1.112 + }; 1.113 + 1.114 + class DnDListener: public MouseListener { 1.115 + public: 1.116 + DnDListener(nsFileControlFrame* aFrame) 1.117 + : MouseListener(aFrame) 1.118 + {} 1.119 + 1.120 + NS_DECL_NSIDOMEVENTLISTENER 1.121 + 1.122 + static bool IsValidDropData(nsIDOMDragEvent* aEvent); 1.123 + }; 1.124 + 1.125 + virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE 1.126 + { 1.127 + return nsBlockFrame::IsFrameOfType(aFlags & 1.128 + ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock)); 1.129 + } 1.130 + 1.131 + /** 1.132 + * The text box input. 1.133 + * @see nsFileControlFrame::CreateAnonymousContent 1.134 + */ 1.135 + nsCOMPtr<nsIContent> mTextContent; 1.136 + /** 1.137 + * The browse button input. 1.138 + * @see nsFileControlFrame::CreateAnonymousContent 1.139 + */ 1.140 + nsCOMPtr<nsIContent> mBrowse; 1.141 + 1.142 + /** 1.143 + * Drag and drop mouse listener. 1.144 + * This makes sure we don't get used after destruction. 1.145 + */ 1.146 + nsRefPtr<DnDListener> mMouseListener; 1.147 + 1.148 +protected: 1.149 + /** 1.150 + * Sync the disabled state of the content with anonymous children. 1.151 + */ 1.152 + void SyncDisabledState(); 1.153 + 1.154 + /** 1.155 + * Updates the displayed value by using aValue. 1.156 + */ 1.157 + void UpdateDisplayedValue(const nsAString& aValue, bool aNotify); 1.158 +}; 1.159 + 1.160 +#endif // nsFileControlFrame_h___