changeset 655:76b081fc0a71

merge
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Mon, 08 Dec 2008 16:32:27 +0100
parents 6e097d44a597 (current diff) 49ed70ecc779 (diff)
children 5394d3d66a3f
files src/form.cc src/html.cc
diffstat 9 files changed, 136 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Dec 07 22:20:39 2008 +0100
+++ b/ChangeLog	Mon Dec 08 16:32:27 2008 +0100
@@ -16,6 +16,8 @@
  - Switched a_UIcmd_save() to take its URL from history (not location bar).
  - Set prefs.vw_fontname as deafult font for the UI.
  - Fix: recover page focus when clicking-out of a widget.
+ - Fixed a segfault bug in the test/ directory.
+ - Set middle click to submit in a new TAB. (Helps to keep form data!)
    Patches: place (AKA corvid)
 +- Switched SSL-enabled to configure.in (./configure --enable-ssl).
  - Standardised the installation of dpid/dpidrc with auto* tools.
@@ -29,11 +31,14 @@
    Patch: Justus Winter
 +- Reduced warnings with gcc-4.3.
    Patch: Thomas Orgis
++- Made the parser recognize "[^ ]/>"-terminated XML elements.
+   Patch: Johannes Hofmann
 +- Added the "middle_click_drags_page" dillorc option.
    Patch: Jorge Arellano, Thomas Orgis
 +- Set the File menu label to hide when the File menu-button is shown.
  ? Trying a new iconv() test in configure.in.
  - Allowed the rc parser to skip whitespace around the equal sign.
+ - Fixed the parser not to call Html_tag_close_* functions twice.
    Patches: Jorge Arellano
 
 dw
--- a/dw/fltkui.cc	Sun Dec 07 22:20:39 2008 +0100
+++ b/dw/fltkui.cc	Mon Dec 08 16:32:27 2008 +0100
@@ -286,11 +286,47 @@
    }
 }
 
+/*
+ * Get FLTK state and translate to dw
+ *
+ * TODO: find a good home for this and the fltkviewbase.cc original.
+ */
+static core::ButtonState getDwButtonState ()
+{
+   int s1 = ::fltk::event_state ();
+   int s2 = (core::ButtonState)0;
+   
+   if(s1 & ::fltk::SHIFT)   s2 |= core::SHIFT_MASK;
+   if(s1 & ::fltk::CTRL)    s2 |= core::CONTROL_MASK;
+   if(s1 & ::fltk::ALT)     s2 |= core::META_MASK;
+   if(s1 & ::fltk::BUTTON1) s2 |= core::BUTTON1_MASK;
+   if(s1 & ::fltk::BUTTON2) s2 |= core::BUTTON2_MASK;
+   if(s1 & ::fltk::BUTTON3) s2 |= core::BUTTON3_MASK;
+
+   return (core::ButtonState)s2;
+}
+
+static void setButtonEvent(dw::core::EventButton *event)
+{
+   event->xCanvas = ::fltk::event_x();
+   event->yCanvas = ::fltk::event_y();
+   event->state = getDwButtonState();
+   event->button = ::fltk::event_button();
+   event->numPressed = ::fltk::event_clicks() + 1;
+}
+
 void FltkLabelButtonResource::widgetCallback (::fltk::Widget *widget,
                                               void *data)
 {
-   if (widget->when () & ::fltk::WHEN_RELEASE)
-      ((FltkLabelButtonResource*)data)->emitActivate ();
+   if ((widget->when () & ::fltk::WHEN_RELEASE) &&
+       ((::fltk::event_key() == ::fltk::ReturnKey) ||
+        (::fltk::event_button() == ::fltk::LeftButton ||
+         ::fltk::event_button() == ::fltk::MiddleButton))) {
+      FltkLabelButtonResource *lbr = (FltkLabelButtonResource*) data;
+      dw::core::EventButton event;
+      setButtonEvent(&event);
+      lbr->emitClicked(&event);
+   }
 }
 
 const char *FltkLabelButtonResource::getLabel ()
@@ -336,12 +372,15 @@
 {
    FltkComplexButtonResource *res = (FltkComplexButtonResource*)data;
 
-   /* would be best not to send click pos. if the image could not be loaded */
-   if (::fltk::event() == ::fltk::RELEASE &&
-       ::fltk::event_button() == ::fltk::LeftButton) {
+   if (widget->when() == ::fltk::WHEN_RELEASE &&
+       ((::fltk::event_key() == ::fltk::ReturnKey) ||
+        (::fltk::event_button() == ::fltk::LeftButton ||
+         ::fltk::event_button() == ::fltk::MiddleButton))) {
       res->click_x = ::fltk::event_x();
       res->click_y = ::fltk::event_y();
-      res->emitActivate ();
+      dw::core::EventButton event;
+      setButtonEvent(&event);
+      res->emitClicked(&event);
    } else {
       ((FltkViewBase*)res->lastFlatView)->handle(::fltk::event());
    }
--- a/dw/ui.cc	Sun Dec 07 22:20:39 2008 +0100
+++ b/dw/ui.cc	Mon Dec 08 16:32:27 2008 +0100
@@ -211,21 +211,17 @@
 {
    ((ClickedReceiver*)receiver)
       ->clicked ((ButtonResource*)((Pointer*)argv[0])->getValue (),
-                 ((Integer*)argv[1])->getValue (),
-                 ((Integer*)argv[2])->getValue (),
-                 ((Integer*)argv[3])->getValue ());
+                 (EventButton*)((Pointer*)argv[1])->getValue());
    return false;
 }
 
 void ButtonResource::ClickedEmitter::emitClicked (ButtonResource *resource,
-                                                  int buttonNo, int x, int y)
+                                                  EventButton *event)
 {
-   Integer i1 (buttonNo);
-   Integer i2 (x);
-   Integer i3 (y);
-   Pointer p (resource);
-   Object *argv[4] = { &p, &i1, &i2, &i3 };
-   emitVoid (0, 4, argv);
+   Pointer p1 (resource);
+   Pointer p2 (event);
+   Object *argv[2] = { &p1, &p2 };
+   emitVoid (0, 2, argv);
 }
 
 // ----------------------------------------------------------------------
--- a/dw/ui.hh	Sun Dec 07 22:20:39 2008 +0100
+++ b/dw/ui.hh	Mon Dec 08 16:32:27 2008 +0100
@@ -334,8 +334,7 @@
    class ClickedReceiver: public lout::signal::Receiver
    {
    public:
-      virtual void clicked (ButtonResource *resource, int buttonNo, int x,
-                            int y) = 0;
+      virtual void clicked (ButtonResource *resource, EventButton *event) = 0;
    };
 
 private:
@@ -347,14 +346,14 @@
    public:
       inline void connectClicked (ClickedReceiver *receiver) {
          connect (receiver); }
-      void emitClicked (ButtonResource *resource, int buttonNo, int x, int y);
+      void emitClicked (ButtonResource *resource, EventButton *event);
    };
 
    ClickedEmitter clickedEmitter;
 
 protected:
-   inline void emitClicked (int buttonNo, int x, int y) {
-      return clickedEmitter.emitClicked (this, buttonNo, x, y); }
+   inline void emitClicked (EventButton *event) {
+      clickedEmitter.emitClicked (this, event); }
 
 public:
    inline void connectClicked (ClickedReceiver *receiver) {
--- a/src/form.cc	Sun Dec 07 22:20:39 2008 +0100
+++ b/src/form.cc	Mon Dec 08 16:32:27 2008 +0100
@@ -75,8 +75,8 @@
    friend class DilloHtmlInput;
 
    DilloHtml *html;
-   void eventHandler(Resource *resource);
-   void submit(DilloHtmlInput *active_input);
+   void eventHandler(Resource *resource, EventButton *event);
+   void submit(DilloHtmlInput *active_input, EventButton *event);
    DilloUrl *buildQueryUrl(DilloHtmlInput *active_input);
    Dstr *buildQueryData(DilloHtmlInput *active_submit);
    char *makeMultipartBoundary(iconv_t char_encoder,
@@ -128,7 +128,7 @@
    void activate (Resource *resource);
    void enter (Resource *resource);
    void leave (Resource *resource);
-   void clicked (ButtonResource *resource, int buttonNo, int x, int y);
+   void clicked (ButtonResource *resource, EventButton *event);
 };
 
 class DilloHtmlInput {
@@ -150,7 +150,7 @@
 
 private:
    void connectTo(DilloHtmlReceiver *form_receiver);
-   void activate(DilloHtmlForm *form, bool entry_input_submits);
+   void activate(DilloHtmlForm *form, int num_entry_fields,EventButton *event);
    void readFile(BrowserWindow *bw);
 
 public:
@@ -947,14 +947,12 @@
       delete(form_receiver);
 }
 
-void DilloHtmlForm::eventHandler(Resource *resource)
+void DilloHtmlForm::eventHandler(Resource *resource, EventButton *event)
 {
    MSG("DilloHtmlForm::eventHandler\n");
    DilloHtmlInput *input = getInput(resource);
    if (input) {
-      bool entry_input_submits = prefs.enterpress_forces_submit ||
-                                 num_entry_fields == 1;
-      input->activate (this, entry_input_submits);
+      input->activate (this, num_entry_fields, event);
    } else {
       MSG("DilloHtmlForm::eventHandler: ERROR, input not found!\n");
    }
@@ -964,11 +962,21 @@
  * Submit.
  * (Called by eventHandler())
  */
-void DilloHtmlForm::submit(DilloHtmlInput *active_input)
+void DilloHtmlForm::submit(DilloHtmlInput *active_input, EventButton *event)
 {
    DilloUrl *url = buildQueryUrl(active_input);
    if (url) {
-      a_Nav_push(html->bw, url);
+      if (event && event->button == 2) {
+         if (prefs.middle_click_opens_new_tab) {
+            int focus = prefs.focus_new_tab ? 1 : 0;
+            if (event->state == SHIFT_MASK) focus = !focus;
+            a_UIcmd_open_url_nt(html->bw, url, focus);
+         } else {
+            a_Nav_push_nw(html->bw, url);
+         }
+      } else {
+         a_Nav_push(html->bw, url);
+      }
       a_Url_free(url);
    }
    // /* now, make the rendered area have its focus back */
@@ -1479,7 +1487,7 @@
 
 void DilloHtmlReceiver::activate (Resource *resource)
 {
-   form->eventHandler(resource);
+   form->eventHandler(resource, NULL);
 }
 
 /*
@@ -1515,9 +1523,9 @@
 }
 
 void DilloHtmlReceiver::clicked (ButtonResource *resource,
-                                 int buttonNo, int x, int y)
+                                 EventButton *event)
 {
-// form->eventHandler(resource, x, y);
+   form->eventHandler(resource, event);
 }
 
 /*
@@ -1566,56 +1574,52 @@
  */
 void DilloHtmlInput::connectTo(DilloHtmlReceiver *form_receiver)
 {
-   Resource *resource = NULL;
-   if (embed)
-      resource = embed->getResource ();
-   switch (type) {
-   case DILLO_HTML_INPUT_UNKNOWN:
-   case DILLO_HTML_INPUT_HIDDEN:
-   case DILLO_HTML_INPUT_CHECKBOX:
-   case DILLO_HTML_INPUT_RADIO:
-   case DILLO_HTML_INPUT_BUTTON:
-   case DILLO_HTML_INPUT_TEXTAREA:
-   case DILLO_HTML_INPUT_SELECT:
-   case DILLO_HTML_INPUT_SEL_LIST:
-      // do nothing
-      break;
-   case DILLO_HTML_INPUT_TEXT:
-   case DILLO_HTML_INPUT_PASSWORD:
-   case DILLO_HTML_INPUT_INDEX:
-   case DILLO_HTML_INPUT_SUBMIT:
-   case DILLO_HTML_INPUT_RESET:
-   case DILLO_HTML_INPUT_BUTTON_SUBMIT:
-   case DILLO_HTML_INPUT_BUTTON_RESET:
-   case DILLO_HTML_INPUT_IMAGE:
-   case DILLO_HTML_INPUT_FILE:
-      if (resource)
-         resource->connectActivate (form_receiver);
-      break;
+   Resource *resource;
+   if (embed && (resource = embed->getResource())) {
+      switch (type) {
+         case DILLO_HTML_INPUT_UNKNOWN:
+         case DILLO_HTML_INPUT_HIDDEN:
+         case DILLO_HTML_INPUT_CHECKBOX:
+         case DILLO_HTML_INPUT_RADIO:
+         case DILLO_HTML_INPUT_BUTTON:
+         case DILLO_HTML_INPUT_TEXTAREA:
+         case DILLO_HTML_INPUT_SELECT:
+         case DILLO_HTML_INPUT_SEL_LIST:
+            // do nothing
+            break;
+         case DILLO_HTML_INPUT_SUBMIT:
+         case DILLO_HTML_INPUT_RESET:
+         case DILLO_HTML_INPUT_BUTTON_SUBMIT:
+         case DILLO_HTML_INPUT_BUTTON_RESET:
+         case DILLO_HTML_INPUT_IMAGE:
+         case DILLO_HTML_INPUT_FILE:
+            ((ButtonResource *)resource)->connectClicked (form_receiver);
+         case DILLO_HTML_INPUT_TEXT:
+         case DILLO_HTML_INPUT_PASSWORD:
+         case DILLO_HTML_INPUT_INDEX:
+            resource->connectActivate (form_receiver);
+            break;
+         break;
+      }
    }
 }
 
 /*
  * Activate a form
  */
-void DilloHtmlInput::activate(DilloHtmlForm *form, bool entry_input_submits)
+void DilloHtmlInput::activate(DilloHtmlForm *form, int num_entry_fields,
+                              EventButton *event)
 {
-   switch (type) {
-   case DILLO_HTML_INPUT_TEXT:
-   case DILLO_HTML_INPUT_PASSWORD:
-      if (entry_input_submits)
-         form->submit (this);
-      break;
-   case DILLO_HTML_INPUT_FILE:
+   if (type == DILLO_HTML_INPUT_FILE) {
       readFile (form->html->bw);
-      break;
-   case DILLO_HTML_INPUT_RESET:
-   case DILLO_HTML_INPUT_BUTTON_RESET:
-      form->reset ();
-      break;
-   default:
-      form->submit (this);
-      break;
+   } else if (type == DILLO_HTML_INPUT_RESET ||
+              type == DILLO_HTML_INPUT_BUTTON_RESET) {
+      form->reset();
+   } else if ((type != DILLO_HTML_INPUT_TEXT &&
+               type != DILLO_HTML_INPUT_PASSWORD) ||
+              prefs.enterpress_forces_submit ||
+              num_entry_fields == 1) {
+      form->submit(this, event);
    }
 }
 
--- a/src/html.cc	Sun Dec 07 22:20:39 2008 +0100
+++ b/src/html.cc	Mon Dec 08 16:32:27 2008 +0100
@@ -464,7 +464,6 @@
    pre_column = 0;
    PreFirstChar = false;
    PrevWasCR = false;
-   PrevWasOpenTag = false;
    PrevWasSPC = false;
    InVisitedLink = false;
    ReqTagClose = false;
@@ -1176,7 +1175,6 @@
       }
    }
 
-   html->PrevWasOpenTag = false;
    html->PrevWasSPC = false;
    if (html->InFlags & IN_LI)
       html->WordAfterLI = true;
@@ -1310,6 +1308,7 @@
 
          /* Close this and only this tag */
          html->CloseOneTag = true;
+         MSG("Close: %*s%s\n", html->stack->size()," ",Tags[toptag_idx].name);
          Tags[toptag_idx].close (html, toptag_idx);
       }
 
@@ -3305,6 +3304,7 @@
       if (tag_idx != new_idx || IsCloseTag) {
          /* implicit open */
          Html_force_push_tag(html, tag_idx);
+         MSG("Open : %*s%s\n", html->stack->size()," ",Tags[tag_idx].name);
          Tags[tag_idx].open (html, tag, strlen(tag));
       }
    }
@@ -3317,6 +3317,7 @@
          if (tag_idx != new_idx || IsCloseTag) {
             /* implicit open of the head element */
             Html_force_push_tag(html, tag_idx);
+            MSG("Open : %*s%s\n", html->stack->size()," ",Tags[tag_idx].name);
             Tags[tag_idx].open (html, tag, strlen(tag));
          }
       }
@@ -3326,13 +3327,14 @@
       if (html->InFlags & IN_HEAD) {
          tag = "</head>";
          tag_idx = a_Html_tag_index(tag + 2);
-         Tags[tag_idx].close (html, tag_idx);
+         Html_tag_cleanup_at_close(html, tag_idx);
       }
       tag = "<body>";
       tag_idx = a_Html_tag_index(tag + 1);
       if (tag_idx != new_idx || IsCloseTag) {
          /* implicit open */
          Html_force_push_tag(html, tag_idx);
+         MSG("Open : %*s%s\n", html->stack->size()," ",Tags[tag_idx].name);
          Tags[tag_idx].open (html, tag, strlen(tag));
       }
    }
@@ -3385,6 +3387,7 @@
       Html_push_tag(html, ni);
 
       html->styleEngine->startElement (ni);
+      MSG("Open : %*s%s\n", html->stack->size(), " ", Tags[ni].name);
 
       /* Now parse attributes that can appear on any tag */
       if (tagsize >= 8 &&        /* length of "<t id=i>" */
@@ -3433,9 +3436,6 @@
       if (html->stop_parser)
          break;
 
-      /* let the parser know this was an open tag */
-      html->PrevWasOpenTag = true;
-
       /* Request inmediate close for elements with forbidden close tag. */
       /* TODO: XHTML always requires close tags. A simple implementation
        * of the commented clause below will make it work. */
@@ -3450,12 +3450,11 @@
       /* Test for </x>, ReqTagClose, <x /> and <x/> */
       if (*start == '/' ||                                      /* </x>    */
           html->ReqTagClose ||                                  /* request */
-          (tag[tagsize - 2] == '/')) {                            /* XML:    */
+          tag[tagsize - 2] == '/') {                            /* XML     */
    
-         Tags[ni].close (html, ni);
+         Html_tag_cleanup_at_close(html, ni);
 //         html->styleEngine->endElement (ni);
          /* This was a close tag */
-         html->PrevWasOpenTag = false;
          html->ReqTagClose = false;
       }
    }
--- a/src/jpeg.c	Sun Dec 07 22:20:39 2008 +0100
+++ b/src/jpeg.c	Mon Dec 08 16:32:27 2008 +0100
@@ -278,14 +278,14 @@
       /* decompression step 3 (see libjpeg.doc) */
       if (jpeg_read_header(&(jpeg->cinfo), TRUE) != JPEG_SUSPENDED) {
          type = DILLO_IMG_TYPE_GRAY;
-         if (jpeg->cinfo.num_components == 1)
+         if (jpeg->cinfo.num_components == 1) {
             type = DILLO_IMG_TYPE_GRAY;
-         else if (jpeg->cinfo.num_components == 3)
+         } else if (jpeg->cinfo.num_components == 3) {
             type = DILLO_IMG_TYPE_RGB;
-         else
+         } else {
             _MSG("jpeg: can't handle %d component images\n",
                  jpeg->cinfo.num_components);
-
+         }
          /*
           * If a multiple-scan image is not completely in cache,
           * use progressive display, updating as it arrives.
--- a/test/form.cc	Sun Dec 07 22:20:39 2008 +0100
+++ b/test/form.cc	Mon Dec 08 16:32:27 2008 +0100
@@ -60,7 +60,7 @@
    this->values = new const char*[n + 1];
    for(int i = 0; i < n; i++)
       this->values[i] = strdup (values[i]);
-   values[n] = 0;
+   this->values[n] = 0;
 }
 
 Form::RadioButtonResourceDecorator::~RadioButtonResourceDecorator ()
@@ -165,9 +165,9 @@
 }
       
 void Form::FormClickedReceiver::clicked (ButtonResource *resource,
-                                         int buttonNo, int x, int y)
+                                         dw::core::EventButton *event)
 {
-   form->send (name, value, x, y);
+   form->send (name, value, event->xCanvas, event->yCanvas);
 }
 
 Form::Form ()
--- a/test/form.hh	Sun Dec 07 22:20:39 2008 +0100
+++ b/test/form.hh	Mon Dec 08 16:32:27 2008 +0100
@@ -130,8 +130,8 @@
       FormClickedReceiver (Form *form, const char *name, const char *value);
       ~FormClickedReceiver ();
       
-      void clicked (dw::core::ui::ButtonResource *resource, int buttonNo,
-                    int x, int y);
+      void clicked(dw::core::ui::ButtonResource *resource,
+                   dw::core::EventButton *event);
    };
 
    lout::container::typed::List <ResourceDecorator> *resources;