惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Spread Privacy
Spread Privacy
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Forbes - Security
Forbes - Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Last Watchdog
The Last Watchdog
SecWiki News
SecWiki News
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Secure Thoughts
WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
Security Latest
Security Latest
TaoSecurity Blog
TaoSecurity Blog
Cyberwarzone
Cyberwarzone
S
SegmentFault 最新的问题
Cloudbric
Cloudbric
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
H
Hacker News: Front Page
C
Cybersecurity and Infrastructure Security Agency CISA
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
AWS News Blog
AWS News Blog
AI
AI
G
GRAHAM CLULEY
IT之家
IT之家
P
Privacy & Cybersecurity Law Blog
L
Lohrmann on Cybersecurity
Last Week in AI
Last Week in AI
D
Docker
Recent Announcements
Recent Announcements
O
OpenAI News
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
Troy Hunt's Blog
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic

Virtual Reality

Implementing WebXR in WebKit for WPE A New Way to Browse: Eye Tracking Comes to Wolvic! Flexbox Cats (a.k.a fixing images in flexbox) Closing the gap (in flexbox 😇) Automatizing the Grid BlinkOn 3 I'm attending BlinkOn3 Grids everywhere! Adventures in the Grid http://publicsuffix.org support coming to libsoup ReSiStance 0.9.2 released ReSiStance 0.8 with Google Reader support WebKitGtk+ HTTP cache ready! ReSiStance 0.5 released ReSiStance with WebKitGtk inside Vive la ReSiStance! Tinymail 1.0 released The Postman always rings twice Some Modest sir? Sure, with Sugar please Moblin support for Tinymail Dear GMail IMAP server developers Another One Bites the Dust Modest with BODYSTRUCTURE support Speed, speed, speed !!! The beauty of git GCDS day #3 (a.k.a. GUADEC day #2) GCDS day #2 (a.k.a. GUADEC day #1) Igalia' new office party Modest @ FreeNode Modest Reloaded Back from GUADEC Get in touch Modest released! JHBuild and SVN problem Our little babies Igalia in the news Be Modest my friend Our dreams came true I want my GConf notifications Faster is better They're coming, don't let them go Dancing with mailboxes Drag and drop with sorted tree models (2) Drag and drop with sorted tree models Not so tiny ChangeLog Turn a GtkMenuBar into a GtkMenu Not so tiny(mail) Ekiga builds 😀 The 3.60 happiness movement GNOME 2.16 is dead. Long live GNOME 2.18 Lightweight apps Bye bye, Pluto Back to home/work/sound The real (virtual?) telepathy Mozilla Thunderbird 1 Evolution 0 What is a galago? Very special numbers Again with some DBUS stuff Gedit hacking; porting gedit to use D-BUS
Improving the editing code in WebKit
svillar · 2013-03-23 · via Virtual Reality

For a while now Igalia and Bloomberg have been collaborating to advance Web technologies. As part of that, I’ve been lately involved on improving some editing capabilities of WebKit (posts to follow soon).

As you probably know, in HTML5 any element can be editable. The feature was introduced some time ago, but was finally standardized by the WHATWG. It’s as easy as adding the attribute contenteditable=true and voilà, the magic unfolds (check it out!!!).

That’s indeed a very powerful feature that allows you to create fast and full-featured rich text editors on the Web. Thing is that, although the contenteditable is standardized, some of the behaviors are not, and thus, each Web engine must provide the one it considers the most correct.

Let me show an example of the above. Imagine that you have the typical HTML bulleted list but inside an editable content element (like a <div>). It’d look like something like this:

  • one
  • two
  • three
  • four

Nothing unusual so far. Now imagine that you select the item “two” and then drag it to the end of “four”. What would be the expected behavior? There is no clear answer to that, you might think that one possible outcome could be:

  • one
  • three
  • fourtwo

which matches Firefox behavior (and WebKit’s as well before I landed this). Another possible result would be this one:

  • one
  • three
  • four
  • two

Both of them seem pretty sensible, the question is whether you consider that you’re dragging just some text, or a text inside a <li> element. It is not an easy decision, so let’s examine some other cases, for example, what happens if we try with two items instead of just one?. In that case (assuming we select “two” and “three” and drop them after “four”)  the result is the following:

  • one
  • four
  • two
  • three

So despite apparently being both outcomes equally correct, it seems that the behavior is a bit inconsistent depending on the number of items you select. I don’t know how this is implemented in Firefox but I’ll try to explain why WebKit was behaving like that.

WebKit is actually pretty smart when dealing with this kind of operations. When doing a drag and drop of a selection, WebKit builds a markup representation (see this file for further details) of the selected contents. In the first case (one item selected) WebKit detects that the selection starts and ends inside the same node (a text element). That’s why the generated markup does not include any <li> tags, and thus, the content is pasted at the end of the “four” item as text.

In the case of multiple item selection, WebKit traverses the DOM tree looking for a common ancestor of the selected nodes in order to build a proper serialized markup representation of the data that is dragged. As you might have deduced, that operation generates a markup that does include all the nodes it finds until the common ancestor is reached (to preserve the structure and appearance). So instead of having a simple two we’d end up with something similar to <li>two</li><li>three</li> for the multiple selection case.

The actual code is a bit more complex than just “get this markup and insert it into the document” because it has to deal with several corner cases and also needs to perform some cleanups after the move operations. Also the generated markup is much more complex (for the single selected item the markup is normally a <span> element which includes styling data among other stuff) but I simplified it for the sake of simplicity.

So after some work (tracked in bug 111556) I came up with a solution that effectively makes WebCore’s editing code to behave the same way independently of the number of selected list items (note that partial selections inside a list item are not affected by this change).

I’d like to thank Ryosuke Niwa for his insightful reviews and Igalia for giving me the chance to work on exciting stuff around WebKit.