blob: 80ca01dd271c72818d330a34a568adaf166c22fa [file] [log] [blame]
Andrew Bonventre78792e82016-03-04 17:48:22 -05001<!--
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04002@license
Andrew Bonventre78792e82016-03-04 17:48:22 -05003Copyright (C) 2015 The Android Open Source Project
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16-->
17
18<link rel="import" href="../../../bower_components/polymer/polymer.html">
Kasper Nilsson380bf8b2017-08-03 15:16:20 -070019<link rel="import" href="../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html">
Viktar Donicha28dee062017-11-10 16:03:13 -080020<link rel="import" href="../../../styles/shared-styles.html">
Andrew Bonventre78792e82016-03-04 17:48:22 -050021<link rel="import" href="../../shared/gr-button/gr-button.html">
Viktar Donich0f02cda2016-06-01 11:41:47 -070022<link rel="import" href="../gr-diff-builder/gr-diff-builder.html">
Ole Rehmsenc4d62572018-11-08 09:07:35 +010023<link rel="import" href="../gr-diff-comment-thread-group/gr-diff-comment-thread-group.html">
Viktar Donichab1b2112016-06-10 12:47:57 -070024<link rel="import" href="../gr-diff-highlight/gr-diff-highlight.html">
Viktar Doniche1341972016-06-09 16:39:17 -070025<link rel="import" href="../gr-diff-selection/gr-diff-selection.html">
Kasper Nilsson889ca952018-04-18 12:06:23 +020026<link rel="import" href="../gr-syntax-themes/gr-syntax-theme.html">
Andrew Bonventre78792e82016-03-04 17:48:22 -050027
Viktar Donich1057e052017-05-12 11:24:31 -070028<script src="../../../scripts/hiddenscroll.js"></script>
29
Andrew Bonventre78792e82016-03-04 17:48:22 -050030<dom-module id="gr-diff">
31 <template>
Becky Siegelb159a7f2017-06-01 15:31:55 -070032 <style include="shared-styles">
Becky Siegela4fc6de2017-06-05 14:40:54 -070033 :host(.no-left) .sideBySide ::content .left,
34 :host(.no-left) .sideBySide ::content .left + td,
35 :host(.no-left) .sideBySide ::content .right:not([data-value]),
36 :host(.no-left) .sideBySide ::content .right:not([data-value]) + td {
Viktar Donichc282d7b2016-08-10 11:53:12 -070037 display: none;
38 }
Ole Rehmsenec1b3512018-11-08 09:12:48 +010039 ::slotted(*) .thread-group {
40 display: block;
41 max-width: var(--content-width, 80ch);
42 white-space: normal;
43 }
Andrew Bonventre78792e82016-03-04 17:48:22 -050044 .diffContainer {
Andrew Bonventre78792e82016-03-04 17:48:22 -050045 display: flex;
Kasper Nilsson86b28f42018-06-25 20:44:19 -070046 font-family: var(--monospace-font-family);
Becky Siegel7fc77622017-11-28 15:49:20 -080047 @apply --diff-container-styles;
Andrew Bonventre78792e82016-03-04 17:48:22 -050048 }
Viktar Donich1057e052017-05-12 11:24:31 -070049 .diffContainer.hiddenscroll {
Kasper Nilsson83d8aac2018-04-17 13:39:50 +020050 margin-bottom: .8em;
Viktar Donich1057e052017-05-12 11:24:31 -070051 }
Andrew Bonventre2aa22122016-03-25 16:48:13 -040052 table {
53 border-collapse: collapse;
Kasper Nilssonc8280982018-04-11 15:32:06 -070054 border-right: 1px solid var(--border-color);
Wyatt Allen32b03fc2016-08-05 15:56:33 -070055 table-layout: fixed;
Andrew Bonventre78792e82016-03-04 17:48:22 -050056 }
Viktar Doniche1341972016-06-09 16:39:17 -070057 .lineNum {
Kasper Nilsson83d8aac2018-04-17 13:39:50 +020058 background-color: var(--table-header-background-color);
Andrew Bonventre2aa22122016-03-25 16:48:13 -040059 }
Wyatt Allen88678da2016-05-23 17:18:43 -070060 .image-diff .gr-diff {
61 text-align: center;
62 }
63 .image-diff img {
Kasper Nilsson2a3f59f2018-07-25 14:01:14 -070064 box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
Wyatt Allen88678da2016-05-23 17:18:43 -070065 max-width: 50em;
Kasper Nilsson2a3f59f2018-07-25 14:01:14 -070066 }
67 .image-diff .right.lineNum {
68 border-left: 1px solid var(--border-color);
Wyatt Allen88678da2016-05-23 17:18:43 -070069 }
Wyatt Allenbae435c2017-11-27 10:07:44 -080070 .image-diff label,
71 .binary-diff label {
Wyatt Allen88678da2016-05-23 17:18:43 -070072 font-family: var(--font-family);
73 font-style: italic;
74 }
Kasper Nilsson40ea3ad2017-06-06 16:59:22 -070075 .diff-row {
76 outline: none;
77 }
Wyatt Allen72b87fc2016-05-16 14:40:51 -070078 .diff-row.target-row.target-side-left .lineNum.left,
79 .diff-row.target-row.target-side-right .lineNum.right,
80 .diff-row.target-row.unified .lineNum {
Kasper Nilsson83d8aac2018-04-17 13:39:50 +020081 background-color: var(--diff-selection-background-color);
Kasper Nilsson92ad99f2018-04-16 10:15:33 +020082 color: var(--primary-text-color);
Wyatt Allen72b87fc2016-05-16 14:40:51 -070083 }
Andrew Bonventre2aa22122016-03-25 16:48:13 -040084 .blank,
85 .content {
Kasper Nilssonc4f41032018-04-16 11:42:56 +020086 background-color: var(--view-background-color);
Andrew Bonventre2aa22122016-03-25 16:48:13 -040087 }
Wyatt Allene3ef1da2018-08-28 16:28:26 -070088 .image-diff .content {
89 background-color: var(--table-header-background-color);
90 }
Becky Siegele7d19a92016-10-31 14:35:35 -070091 .full-width {
92 width: 100%;
93 }
Becky Siegeldc462182016-11-02 17:57:16 -070094 .full-width .contentText {
95 white-space: pre-wrap;
96 word-wrap: break-word;
97 }
Andrew Bonventre2aa22122016-03-25 16:48:13 -040098 .lineNum,
99 .content {
Becky Siegele7d19a92016-10-31 14:35:35 -0700100 /* Set font size based the user's diff preference. */
Kasper Nilsson86b28f42018-06-25 20:44:19 -0700101 font-size: var(--font-size, var(--font-size-normal));
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400102 vertical-align: top;
103 white-space: pre;
104 }
Wyatt Allenf5f68992018-02-09 13:34:56 -0800105 .contextLineNum,
106 .lineNum {
107 -webkit-user-select: none;
108 -moz-user-select: none;
109 -ms-user-select: none;
110 user-select: none;
111
Kasper Nilssonb0d03d02018-04-16 17:04:22 +0200112 color: var(--deemphasized-text-color);
Becky Siegel727fa5d2017-04-19 16:12:56 -0700113 padding: 0 .5em;
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400114 text-align: right;
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400115 }
Wyatt Allenf5f68992018-02-09 13:34:56 -0800116 .canComment .lineNum {
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400117 cursor: pointer;
118 }
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400119 .content {
Viktar Donich60cbd2f2018-04-11 13:34:40 -0700120 /* Set min width since setting width on table cells still
121 allows them to shrink. Do not set max width because
122 CJK (Chinese-Japanese-Korean) glyphs have variable width */
Andrew Bonventreac802cd2016-04-02 21:53:35 -0400123 min-width: var(--content-width, 80ch);
Becky Siegele7d19a92016-10-31 14:35:35 -0700124 width: var(--content-width, 80ch);
Becky Siegeld7dbed62016-10-12 10:55:26 -0700125 }
Wyatt Allen650c5292016-06-22 17:18:06 -0700126 .content.add .intraline,
Wyatt Allen1e3cd472016-12-21 12:55:21 -0800127 .delta.total .content.add {
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400128 background-color: var(--dark-add-highlight-color);
129 }
Wyatt Allen1e3cd472016-12-21 12:55:21 -0800130 .content.add {
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400131 background-color: var(--light-add-highlight-color);
132 }
Wyatt Allen650c5292016-06-22 17:18:06 -0700133 .content.remove .intraline,
Wyatt Allen1e3cd472016-12-21 12:55:21 -0800134 .delta.total .content.remove {
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400135 background-color: var(--dark-remove-highlight-color);
136 }
Wyatt Allen1e3cd472016-12-21 12:55:21 -0800137 .content.remove {
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400138 background-color: var(--light-remove-highlight-color);
139 }
Alice Kober-Sotzek4cb04e12017-07-20 16:31:02 +0000140 .dueToRebase .content.add .intraline,
141 .delta.total.dueToRebase .content.add {
142 background-color: var(--dark-rebased-add-highlight-color);
143 }
144 .dueToRebase .content.add {
145 background-color: var(--light-rebased-add-highlight-color);
146 }
147 .dueToRebase .content.remove .intraline,
148 .delta.total.dueToRebase .content.remove {
149 background-color: var(--dark-rebased-remove-highlight-color);
150 }
151 .dueToRebase .content.remove {
Kasper Nilsson83d8aac2018-04-17 13:39:50 +0200152 background-color: var(--light-remove-add-highlight-color);
Alice Kober-Sotzek4cb04e12017-07-20 16:31:02 +0000153 }
Luís Oliveira40eb3f42018-01-24 01:31:15 +0000154 .content .contentText:empty:after {
155 /* Newline, to ensure empty lines are one line-height tall. */
Aaron Gabled5d9a132016-12-09 12:30:29 -0800156 content: '\A';
157 }
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400158 .contextControl {
Kasper Nilsson83d8aac2018-04-17 13:39:50 +0200159 background-color: var(--diff-context-control-color);
160 border: 1px solid var(--diff-context-control-border-color);
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400161 }
162 .contextControl gr-button {
Wyatt Allen10979632016-06-01 15:13:33 -0700163 display: inline-block;
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400164 text-decoration: none;
Becky Siegel8b60a512018-03-26 13:18:47 -0700165 --gr-button: {
Kasper Nilssona8409292018-04-30 10:55:13 -0700166 color: var(--deemphasized-text-color);
Becky Siegel8b60a512018-03-26 13:18:47 -0700167 padding: .2em;
168 }
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400169 }
170 .contextControl td:not(.lineNum) {
171 text-align: center;
172 }
Becky Siegel08ca8262017-06-28 16:29:56 -0700173 .displayLine .diff-row.target-row td {
Kasper Nilsson83d8aac2018-04-17 13:39:50 +0200174 box-shadow: inset 0 -1px var(--border-color);
Becky Siegel6a7085e2016-11-02 16:25:53 -0700175 }
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400176 .br:after {
177 /* Line feed */
178 content: '\A';
179 }
180 .tab {
181 display: inline-block;
182 }
Wyatt Allenbe0142c2016-08-25 11:31:42 -0700183 .tab-indicator:before {
Kasper Nilsson83d8aac2018-04-17 13:39:50 +0200184 color: var(--diff-tab-indicator-color);
Wyatt Allenbe0142c2016-08-25 11:31:42 -0700185 /* >> character */
186 content: '\00BB';
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400187 }
Wyatt Allend9705002016-11-17 12:03:51 -0800188 .trailing-whitespace {
189 border-radius: .4em;
Kasper Nilsson83d8aac2018-04-17 13:39:50 +0200190 background-color: var(--diff-trailing-whitespace-indicator);
Wyatt Allend9705002016-11-17 12:03:51 -0800191 }
Kasper Nilssonb4893d02017-04-07 15:52:28 -0700192 #diffHeader {
Kasper Nilsson83d8aac2018-04-17 13:39:50 +0200193 background-color: var(--table-header-background-color);
194 border-bottom: 1px solid var(--border-color);
195 color: var(--link-color);
Kasper Nilssonb4893d02017-04-07 15:52:28 -0700196 font-family: var(--monospace-font-family);
Kasper Nilsson86b28f42018-06-25 20:44:19 -0700197 font-size: var(--font-size, var(--font-size-normal));
Kasper Nilssonb4893d02017-04-07 15:52:28 -0700198 padding: 0.5em 0 0.5em 4em;
199 }
Wyatt Alleneb043442018-08-15 14:13:01 -0700200 #loadingError,
Wyatt Allen6df3f492017-06-13 15:32:51 -0700201 #sizeWarning {
202 display: none;
203 margin: 1em auto;
204 max-width: 60em;
205 text-align: center;
206 }
Wyatt Alleneb043442018-08-15 14:13:01 -0700207 #loadingError {
208 color: var(--error-text-color);
209 }
Wyatt Allen6df3f492017-06-13 15:32:51 -0700210 #sizeWarning gr-button {
211 margin: 1em;
212 }
Wyatt Alleneb043442018-08-15 14:13:01 -0700213 #loadingError.showError,
Wyatt Allen6df3f492017-06-13 15:32:51 -0700214 #sizeWarning.warn {
215 display: block;
216 }
Wyatt Allened628d72017-09-14 09:45:50 -0700217 .target-row td.blame {
Kasper Nilssone46284e2018-04-30 10:14:58 -0700218 background: var(--diff-selection-background-color);
Wyatt Allened628d72017-09-14 09:45:50 -0700219 }
Wyatt Allen03097562017-09-30 14:54:01 +0100220 col.blame {
221 display: none;
222 }
Wyatt Allened628d72017-09-14 09:45:50 -0700223 td.blame {
224 display: none;
225 font-family: var(--font-family);
Kasper Nilsson86b28f42018-06-25 20:44:19 -0700226 font-size: var(--font-size, var(--font-size-normal));
Wyatt Allened628d72017-09-14 09:45:50 -0700227 padding: 0 .5em;
228 white-space: pre;
229 }
Wyatt Allen03097562017-09-30 14:54:01 +0100230 :host(.showBlame) col.blame {
231 display: table-column;
232 }
Wyatt Allened628d72017-09-14 09:45:50 -0700233 :host(.showBlame) td.blame {
234 display: table-cell;
235 }
236 td.blame > span {
237 opacity: 0.6;
238 }
239 td.blame > span.startOfRange {
240 opacity: 1;
241 }
242 td.blame .sha {
243 font-family: var(--monospace-font-family);
244 }
245 .full-width td.blame {
246 overflow: hidden;
247 width: 200px;
248 }
Becky Siegeld3cd1252018-03-19 14:36:52 -0700249 /** Since the line limit position is determined by charachter size, blank
250 lines also need to have the same font size as everything else */
251 .full-width .blank {
Kasper Nilsson86b28f42018-06-25 20:44:19 -0700252 font-size: var(--font-size, var(--font-size-normal));
Becky Siegeld3cd1252018-03-19 14:36:52 -0700253 }
254 /** Support the line length indicator **/
255 .full-width td.content,
256 .full-width td.blank {
Becky Siegel7982f5c2018-03-20 10:40:44 -0700257 /* Base 64 encoded 1x1px of #ddd */
Paladox none0e7367c2018-03-22 18:30:26 +0000258 background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mO8+x8AAr8B3gzOjaQAAAAASUVORK5CYII=');
Becky Siegeld3cd1252018-03-19 14:36:52 -0700259 background-position: var(--line-limit) 0;
260 background-repeat: repeat-y;
261 }
Wyatt Allend13f4182018-08-01 11:57:34 -0700262 .newlineWarning {
263 color: var(--deemphasized-text-color);
264 text-align: center;
265 }
266 .newlineWarning.hidden {
267 display: none;
268 }
Andrew Bonventre78792e82016-03-04 17:48:22 -0500269 </style>
Kasper Nilsson889ca952018-04-18 12:06:23 +0200270 <style include="gr-syntax-theme"></style>
Kasper Nilssonb4893d02017-04-07 15:52:28 -0700271 <div id="diffHeader" hidden$="[[_computeDiffHeaderHidden(_diffHeaderItems)]]">
272 <template
273 is="dom-repeat"
274 items="[[_diffHeaderItems]]">
275 <div>[[item]]</div>
276 </template>
277 </div>
Ole Rehmsenb1a79672018-08-27 22:43:38 +0200278 <div class$="[[_computeContainerClass(loggedIn, viewMode, displayLine)]]"
Viktar Doniche1341972016-06-09 16:39:17 -0700279 on-tap="_handleTap">
Ole Rehmsenb1a79672018-08-27 22:43:38 +0200280 <gr-diff-selection diff="[[diff]]">
Viktar Donichab1b2112016-06-10 12:47:57 -0700281 <gr-diff-highlight
282 id="highlights"
Ole Rehmsenb1a79672018-08-27 22:43:38 +0200283 logged-in="[[loggedIn]]"
Wyatt Allendc8782d2017-07-26 09:32:03 -0700284 comments="{{comments}}">
Viktar Donichab1b2112016-06-10 12:47:57 -0700285 <gr-diff-builder
286 id="diffBuilder"
Wyatt Allendc8782d2017-07-26 09:32:03 -0700287 comments="[[comments]]"
Wyatt Allenf0eb4bb2017-07-31 14:33:16 -0700288 project-name="[[projectName]]"
Ole Rehmsenb1a79672018-08-27 22:43:38 +0200289 diff="[[diff]]"
Becky Siegeleccee3c2017-04-13 14:48:31 -0700290 diff-path="[[path]]"
Ravi Mistryaf1e0f82017-10-10 09:47:26 -0400291 change-num="[[changeNum]]"
292 patch-num="[[patchRange.patchNum]]"
Viktar Donichab1b2112016-06-10 12:47:57 -0700293 view-mode="[[viewMode]]"
Becky Siegele7d19a92016-10-31 14:35:35 -0700294 line-wrapping="[[lineWrapping]]"
Viktar Donichab1b2112016-06-10 12:47:57 -0700295 is-image-diff="[[isImageDiff]]"
Ole Rehmsenb1a79672018-08-27 22:43:38 +0200296 base-image="[[baseImage]]"
297 revision-image="[[revisionImage]]"
Wyatt Allene515ff62018-01-19 17:54:50 -0800298 line-of-interest="[[lineOfInterest]]">
Ole Rehmsen8c8ce2d2018-10-12 16:20:57 +0200299 <slot></slot>
Kasper Nilsson40ea3ad2017-06-06 16:59:22 -0700300 <table
301 id="diffTable"
302 class$="[[_diffTableClass]]"
303 role="presentation"></table>
Viktar Donichab1b2112016-06-10 12:47:57 -0700304 </gr-diff-builder>
305 </gr-diff-highlight>
Viktar Doniche1341972016-06-09 16:39:17 -0700306 </gr-diff-selection>
Andrew Bonventre78792e82016-03-04 17:48:22 -0500307 </div>
Ole Rehmsenb1a79672018-08-27 22:43:38 +0200308 <div class$="[[_computeNewlineWarningClass(_newlineWarning, loading)]]">
Wyatt Allend13f4182018-08-01 11:57:34 -0700309 [[_newlineWarning]]
310 </div>
Ole Rehmsenb1a79672018-08-27 22:43:38 +0200311 <div id="loadingError" class$="[[_computeErrorClass(errorMessage)]]">
312 [[errorMessage]]
Wyatt Alleneb043442018-08-15 14:13:01 -0700313 </div>
Wyatt Allen6df3f492017-06-13 15:32:51 -0700314 <div id="sizeWarning" class$="[[_computeWarningClass(_showWarning)]]">
315 <p>
316 Prevented render because "Whole file" is enabled and this diff is very
Wyatt Allen7e9b0c32018-09-14 17:19:39 -0700317 large (about [[_diffLength]] lines).
Wyatt Allen6df3f492017-06-13 15:32:51 -0700318 </p>
319 <gr-button on-tap="_handleLimitedBypass">
320 Render with limited context
321 </gr-button>
322 <gr-button on-tap="_handleFullBypass">
323 Render anyway (may be slow)
324 </gr-button>
325 </div>
Andrew Bonventre78792e82016-03-04 17:48:22 -0500326 </template>
Andrew Bonventre2aa22122016-03-25 16:48:13 -0400327 <script src="gr-diff-line.js"></script>
328 <script src="gr-diff-group.js"></script>
Andrew Bonventre78792e82016-03-04 17:48:22 -0500329 <script src="gr-diff.js"></script>
330</dom-module>