diff --git a/src/form.cc b/src/form.cc index 8524300..dfeac39 100644 --- a/src/form.cc +++ b/src/form.cc @@ -57,35 +57,11 @@ static Embed *Html_input_image(DilloHtml *html, const char *tag, int tagsize); static void Html_option_finish(DilloHtml *html); -/* - * Typedefs - */ - -typedef enum { - DILLO_HTML_INPUT_UNKNOWN, - DILLO_HTML_INPUT_TEXT, - DILLO_HTML_INPUT_PASSWORD, - DILLO_HTML_INPUT_CHECKBOX, - DILLO_HTML_INPUT_RADIO, - DILLO_HTML_INPUT_IMAGE, - DILLO_HTML_INPUT_FILE, - DILLO_HTML_INPUT_BUTTON, - DILLO_HTML_INPUT_HIDDEN, - DILLO_HTML_INPUT_SUBMIT, - DILLO_HTML_INPUT_RESET, - DILLO_HTML_INPUT_BUTTON_SUBMIT, - DILLO_HTML_INPUT_BUTTON_RESET, - DILLO_HTML_INPUT_SELECT, - DILLO_HTML_INPUT_SEL_LIST, - DILLO_HTML_INPUT_TEXTAREA, - DILLO_HTML_INPUT_INDEX -} DilloHtmlInputType; - /* * Class declarations */ -class DilloHtmlForm { +class DilloHtmlFormImpl : public DilloHtmlForm { friend class DilloHtmlReceiver; friend class DilloHtmlInput; @@ -111,28 +87,33 @@ class DilloHtmlForm { public: //BUG: for now everything is public DilloHtmlMethod method; + DilloHtmlMethod get_method() const override { return method; } + DilloUrl *action; DilloHtmlEnc content_type; + DilloHtmlEnc get_content_type() const override { return content_type; } char *submit_charset; std::vector< std::shared_ptr< DilloHtmlInput > > inputs; + std::vector< std::shared_ptr< DilloHtmlInput > > *get_inputs() override { return &inputs; } + int num_entry_fields; std::unique_ptr< DilloHtmlReceiver > form_receiver; public: - DilloHtmlForm (DilloHtml *html, + DilloHtmlFormImpl (DilloHtml *html, DilloHtmlMethod method, const DilloUrl *action, DilloHtmlEnc content_type, const char *charset, bool enabled); - ~DilloHtmlForm (); + ~DilloHtmlFormImpl () override; std::shared_ptr< DilloHtmlInput > getInput (Resource *resource); std::shared_ptr< DilloHtmlInput > getRadioInput (const char *name); void submit(DilloHtmlInput *active_input, EventButton *event); void reset (); void display_hiddens(bool display); - void addInput(std::unique_ptr< DilloHtmlInput > input, DilloHtmlInputType type); + void addInput(std::unique_ptr< DilloHtmlInput > input, DilloHtmlInputType type) override; void setEnabled(bool enabled); }; @@ -141,11 +122,11 @@ class DilloHtmlReceiver: public Resource::ClickedReceiver { private: - friend class DilloHtmlForm; - DilloHtmlForm* form; + friend class DilloHtmlFormImpl; + DilloHtmlFormImpl* form; public: - DilloHtmlReceiver (DilloHtmlForm* form2) { form = form2; } + DilloHtmlReceiver (DilloHtmlFormImpl* form2) { form = form2; } ~DilloHtmlReceiver () { } private: @@ -157,8 +138,8 @@ private: class DilloHtmlInput { - // DilloHtmlForm::addInput() calls connectTo() - friend class DilloHtmlForm; + // DilloHtmlFormImpl::addInput() calls connectTo() + friend class DilloHtmlFormImpl; public: //BUG: for now everything is public DilloHtmlInputType type; @@ -174,7 +155,7 @@ public: //BUG: for now everything is public private: void connectTo(DilloHtmlReceiver *form_receiver); - void activate(DilloHtmlForm *form, int num_entry_fields,EventButton *event); + void activate(DilloHtmlFormImpl *form, int num_entry_fields,EventButton *event); void readFile(BrowserWindow *bw); public: @@ -250,20 +231,15 @@ public: * Form API */ -DilloHtmlForm *a_Html_form_new (DilloHtml *html, DilloHtmlMethod method, +std::unique_ptr< DilloHtmlForm > a_Html_form_new (DilloHtml *html, DilloHtmlMethod method, const DilloUrl *action, DilloHtmlEnc content_type, const char *charset, bool enabled) { - return new DilloHtmlForm (html, method, action, content_type, charset, + return std::make_unique< DilloHtmlFormImpl > (html, method, action, content_type, charset, enabled); } -void a_Html_form_delete (DilloHtmlForm *form) -{ - delete form; -} - void a_Html_input_delete (DilloHtmlInput *input) { delete input; @@ -271,17 +247,17 @@ void a_Html_input_delete (DilloHtmlInput *input) void a_Html_form_submit2(void *vform) { - ((DilloHtmlForm *)vform)->submit(NULL, NULL); + ((DilloHtmlFormImpl *)vform)->submit(NULL, NULL); } void a_Html_form_reset2(void *vform) { - ((DilloHtmlForm *)vform)->reset(); + ((DilloHtmlFormImpl *)vform)->reset(); } void a_Html_form_display_hiddens2(void *vform, bool display) { - ((DilloHtmlForm *)vform)->display_hiddens(display); + ((DilloHtmlFormImpl *)vform)->display_hiddens(display); } /* @@ -318,7 +294,7 @@ static std::shared_ptr< DilloHtmlInput > Html_get_radio_input(DilloHtml *html, c std::vector< std::shared_ptr< DilloHtmlInput > > *inputs; if (html->InFlags & IN_FORM) - inputs = &html->getCurrentForm()->inputs; + inputs = html->getCurrentForm()->get_inputs(); else inputs = &html->inputs_outside_form; @@ -340,7 +316,7 @@ static std::shared_ptr< DilloHtmlInput > Html_get_current_input(DilloHtml &html) std::vector< std::shared_ptr< DilloHtmlInput > > *inputs; if (html.InFlags & IN_FORM) - inputs = &html.getCurrentForm()->inputs; + inputs = html.getCurrentForm()->get_inputs(); else inputs = &html.inputs_outside_form; @@ -524,11 +500,11 @@ void Html_tag_open_input(DilloHtml *html, const char *tag, int tagsize) bool valid = true; if (html->InFlags & IN_FORM) { DilloHtmlForm *form = html->getCurrentForm(); - if (form->method != DILLO_HTML_METHOD_POST) { + if (form->get_method() != DILLO_HTML_METHOD_POST) { valid = false; BUG_MSG("