Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Side by Side Diff: elements/designer-stage/frame.html

Issue 881243003: Add designer-stage (Closed) Base URL: https://github.com/PolymerLabs/designer2.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!--
2 Copyright 2015 The Polymer Authors. All rights reserved.
3 Use of this source code is governed by a BSD-style
4 license that can be found in the LICENSE file.
5 -->
6 <!doctype html>
7 <html>
8 <head>
9 <!--
10 TODO: remove style
11 -->
12 <style>
13 body {
14 position: relative;
15 margin: 0;
16 padding: 0;
17 }
18 #foo {
19 position: absolute;
20 background: #faa;
21 box-sizing: border-box;
22 }
23 .static {
24 height: 100px;
25 background: blue;
26 border: solid 1px black;
27 box-sizing: border-box;
28 }
29 </style>
30 </head>
31 <body>
32 <!--
33 TODO: remove content
34
35 This is only here for demo / development until there's a way to load conte nt into the frame.
36 -->
37 <div class="static"></div>
38 <div class="static"></div>
39 <div id="foo" style="top: 100px; left: 100px; height: 100px;width: 400px;">H ello Designer</div>
40 <div id="foo" style="top: 300px; left: 100px; height: 100px;width: 400px;">H ello Designer</div>
41 <script>
42 (function() {
43 currentElement = null;
44 token = null;
45
46 window.addEventListener("message", function(e) {
47 switch (e.data.message_type) {
48 case 'setToken':
49 setToken(e);
50 break;
51 case 'selectElement':
52 selectElement(e);
53 break;
54 case 'resizeElement':
55 resizeElement(e);
56 break;
57 }
58 });
59
60 function setToken(e) {
61 if (token != null) {
62 throw new Error('token already set');
63 }
64 token = e.data.token;
65 }
66
67 function sendUpdateSelector(receiver, bounds) {
68 receiver.postMessage({
69 message_type: 'updateSelector',
70 token: token,
71 bounds: {
72 left: bounds.left,
73 top: bounds.top,
74 width: bounds.width,
75 height: bounds.height
76 }
77 }, '*');
78 }
79
80 function sendSelectedElement(receiver, element) {
81 var style = window.getComputedStyle(element);
82 var bounds = element.getBoundingClientRect();
83 receiver.postMessage({
84 message_type: 'seletedElement',
85 token: token,
86 tagName: element.tagName,
87 display: style.display,
88 position: style.position,
89 bounds: {
90 left: bounds.left,
91 top: bounds.top,
92 width: bounds.width,
93 height: bounds.height
94 }
95 }, '*');
96 }
97
98 function selectElement(e) {
99 var data = e.data;
100 currentElement = document.elementFromPoint(data.x, data.y);
101 var bounds = currentElement.getBoundingClientRect();
102 sendSelectedElement(e.source, currentElement);
103 }
104
105 function resizeElement(e) {
106 if (currentElement != null) {
107 var bounds = e.data.bounds;
108 currentElement.style.top = bounds.top + 'px';
109 currentElement.style.left = bounds.left + 'px';
110 currentElement.style.height = bounds.height + 'px';
111 currentElement.style.width = bounds.width + 'px';
112 sendUpdateSelector(e.source, bounds);
113 }
114 }
115 })();
116 </script>
117 </body>
118 </html>
OLDNEW
« elements/designer-stage/designer-stage.html ('K') | « elements/designer-stage/designer-stage.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698