Open Bug 285893 Opened 19 years ago Updated 2 years ago

<head> tag is missing from data present in drag and drop

Categories

(Core :: XUL, enhancement)

x86
Windows 2000
enhancement

Tracking

()

People

(Reporter: dcaruso, Unassigned)

References

(Depends on 1 open bug)

Details

User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113

the <head> tag is not included in the information formated for teh CF_HTML spec 
which mozilla uses for drag and drop on windows systems. For dump of this see 
bug 244685 

The head tag is included from Internet Explorer. Passing the head tag allows 
for importan meta tags to be placed in the drag and drop information and is 
essentail for many applications which utilize this data.

Although the <head> tag is not requred by CF_HTML it is suggested, and clearly 
stated that internet explorer includes this information

Reproducible: Always

Steps to Reproduce:
1.drag a slection from mozilla to an applcation which give a complet dump of 
the drag data for the HTML flavor
2.compare this with adrag from the same page fro internet explorer.

Actual Results:  
 ther eis no <head> elemnt present in the mozilla dump. But there is noe 
present in the Internet explorer dump.

Expected Results:  
provided the <head> element from the document.
Triaging correctly.

I couldn't find an application that gives a complete dump of the clipboard
content to actually verify, but I believe I can trust the reporter on that.

Reporter, it could be useful to include a dump of the data created by mozilla vs
IE to show the missing part. And if you can indicate a way to easily dump the
content ...
Severity: normal → enhancement
Status: UNCONFIRMED → NEW
Component: General → XP Toolkit/Widgets
Ever confirmed: true
Product: Mozilla Application Suite → Core
Version: unspecified → Trunk
OK, the dump by David Gardiner in bug 244685 shows <head> is indeed missing with
mozilla wrt IE. And *maybe* David will be interested in getting a look at that.
What info do you need exactly in the head tag ?

Including the complete original page as you require in bug 285635 would save the
problem. No if we don't want to copy all the page, we need to include only what
is required, so need detailled specification about what must be copied.
Depends on: 285635
I think all CSS definitions that are included in the HEAD should be available in the clipboard/drag and drop data. Currently if there are usages of CSS defs in the BODY, they cannot be used because the definitions are missing. This means that in many cases most of the formatting gets lost when copying from firefox.

To make it short: The CSS definitions should be available in the clipboard data.
If you want to take a look at the raw clipboard data, you can use the little Java tool that I wrote to view the raw clipboard content. Do not expect a great user experience, but it does its job. I displays all available data flavors in a list, and if you select one flavor and press on the "Show Data" button, it will display the clipboard data for the selected flavor as raw text. The see the html content of the clipboard, you must certainly select a flavor that starts with "text/html".

Here we go:

import javax.swing.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.FlavorListener;
import java.awt.datatransfer.FlavorEvent;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.CharBuffer;

/**
 *
 */
public class JClipboardViewer extends JPanel {
  private final Clipboard clipboard;
  private JList jListDataFlavors = new JList();
  private DefaultListModel dataFlavorsListModel = new DefaultListModel();
  private JButton jButtonShowData = new JButton("Show Data");
  private JTextArea jTextAreaContent = new JTextArea();

  public JClipboardViewer() {
    clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.addFlavorListener(new FlavorListener() {
      public void flavorsChanged(FlavorEvent e) {
        updateDataFlavors();
      }
    });
    setLayout(new GridBagLayout());
    add(new JScrollPane(jListDataFlavors), new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
        GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    add(new JScrollPane(jButtonShowData), new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0,
        GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    add(new JScrollPane(jTextAreaContent), new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0,
        GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jListDataFlavors.setModel(dataFlavorsListModel);
    jListDataFlavors.setCellRenderer(new DataFlavorListRenderer());
    jButtonShowData.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        DataFlavor selDataFlavor = (DataFlavor) jListDataFlavors.getSelectedValue();
        if (selDataFlavor != null) {
          try {
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            if (selDataFlavor.isRepresentationClassInputStream()) {
              InputStream inStream = (InputStream) clipboard.getData(selDataFlavor);
              InputStreamReader inputStreamReader = new InputStreamReader(inStream);
              int c = inputStreamReader.read();
              StringBuilder strBuilder = new StringBuilder();
              while (c > 0) {
                strBuilder.append((char) c);
                c = inputStreamReader.read();
              }
              jTextAreaContent.setText(strBuilder.toString());
            } else if (selDataFlavor.isRepresentationClassReader()) {
              Reader reader = (Reader) clipboard.getData(selDataFlavor);
              int c = reader.read();
              StringBuilder strBuilder = new StringBuilder();
              while (c > 0) {
                strBuilder.append((char) c);
                c = reader.read();
              }
              jTextAreaContent.setText(strBuilder.toString());
            } else if (selDataFlavor.isRepresentationClassCharBuffer()) {
              CharBuffer charBuffer = (CharBuffer) clipboard.getData(selDataFlavor);
              jTextAreaContent.setText(charBuffer.toString());
            } else {
              jTextAreaContent.setText("### Cannot interpret data ###");
            }
          } catch (UnsupportedFlavorException ufEx) {
            ufEx.printStackTrace();
          } catch (IOException ioEx) {
            ioEx.printStackTrace();
          }
        }
      }
    });
    updateDataFlavors();
  }

  private void updateDataFlavors() {
    dataFlavorsListModel = new DefaultListModel();
    DataFlavor[] dataFlavors = clipboard.getAvailableDataFlavors();
    for (DataFlavor dataFlavor : dataFlavors) {
      dataFlavorsListModel.addElement(dataFlavor);
    }
    jListDataFlavors.setModel(dataFlavorsListModel);
  }


  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        JFrame frame = new JFrame("ClipboardViewer");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(new JClipboardViewer());
        frame.setSize(600, 480);
        frame.validate();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    });        
  }


  private static class DataFlavorListRenderer extends DefaultListCellRenderer {

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      if (value instanceof DataFlavor) {
        DataFlavor dataFlavor = (DataFlavor) value;
        comp.setText(dataFlavor.getMimeType());
      }
      return comp;
    }

  }


}
The head element should include all attributes which are present in the orignal HTMl document. I applogize for a long overdue response. Life takes many turns.
Assignee: general → nobody
QA Contact: general → xptoolkit.widgets
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.