blob: 038bacbdf9b9e6290ef1908ef604e3a2bf8584bb [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) IBM Corp. 2009 All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Jan Scheffler4a89ed32020-07-29 16:19:1330
Tim van der Lippe18f04892020-03-17 11:39:4031import * as TextUtils from '../text_utils/text_utils.js'; // eslint-disable-line no-unused-vars
Tim van der Lippe2543c5c2020-02-04 11:58:0732import * as UI from '../ui/ui.js';
33
Paul Lewisaa437a52020-01-15 15:11:3034import {SourceFrameImpl} from './SourceFrame.js';
35
Blink Reformat4c46d092018-04-07 15:32:3736/**
37 * @unrestricted
38 */
Paul Lewisaa437a52020-01-15 15:11:3039export class ResourceSourceFrame extends SourceFrameImpl {
Blink Reformat4c46d092018-04-07 15:32:3740 /**
Tim van der Lippe18f04892020-03-17 11:39:4041 * @param {!TextUtils.ContentProvider.ContentProvider} resource
Blink Reformat4c46d092018-04-07 15:32:3742 * @param {boolean=} autoPrettyPrint
Joey Arhar19e85cc2019-01-29 22:07:0243 * @param {!UI.TextEditor.Options=} codeMirrorOptions
Blink Reformat4c46d092018-04-07 15:32:3744 */
Joey Arhar19e85cc2019-01-29 22:07:0245 constructor(resource, autoPrettyPrint, codeMirrorOptions) {
Ingvar Stepanyan1c771842018-10-10 14:35:0846 super(async () => {
Rob Paveza2eb8c142019-10-13 18:02:3847 let content = (await resource.requestContent()).content || '';
Tim van der Lippe1d6e57a2019-09-30 11:55:3448 if (await resource.contentEncoded()) {
Ingvar Stepanyan1c771842018-10-10 14:35:0849 content = window.atob(content);
Tim van der Lippe1d6e57a2019-09-30 11:55:3450 }
Rob Paveza2eb8c142019-10-13 18:02:3851 return {content, isEncoded: false};
Joey Arhar19e85cc2019-01-29 22:07:0252 }, codeMirrorOptions);
Blink Reformat4c46d092018-04-07 15:32:3753 this._resource = resource;
54 this.setCanPrettyPrint(this._resource.contentType().isDocumentOrScriptOrStyleSheet(), autoPrettyPrint);
55 }
56
57 /**
Tim van der Lippe18f04892020-03-17 11:39:4058 * @param {!TextUtils.ContentProvider.ContentProvider} resource
Blink Reformat4c46d092018-04-07 15:32:3759 * @param {string} highlighterType
60 * @param {boolean=} autoPrettyPrint
Tim van der Lippe2543c5c2020-02-04 11:58:0761 * @return {!UI.Widget.Widget}
Blink Reformat4c46d092018-04-07 15:32:3762 */
63 static createSearchableView(resource, highlighterType, autoPrettyPrint) {
Tim van der Lippeb88663f2019-11-07 15:53:2164 return new SearchableContainer(resource, highlighterType, autoPrettyPrint);
Blink Reformat4c46d092018-04-07 15:32:3765 }
66
67 get resource() {
68 return this._resource;
69 }
70
71 /**
72 * @override
Tim van der Lippe2543c5c2020-02-04 11:58:0773 * @param {!UI.ContextMenu.ContextMenu} contextMenu
Blink Reformat4c46d092018-04-07 15:32:3774 * @param {number} lineNumber
75 * @param {number} columnNumber
Andres Olivaresc2d30bd2020-10-25 23:35:1876 * @return {!Promise<void>}
Blink Reformat4c46d092018-04-07 15:32:3777 */
78 populateTextAreaContextMenu(contextMenu, lineNumber, columnNumber) {
79 contextMenu.appendApplicableItems(this._resource);
80 return Promise.resolve();
81 }
Tim van der Lippeb88663f2019-11-07 15:53:2182}
Blink Reformat4c46d092018-04-07 15:32:3783
Tim van der Lippe2543c5c2020-02-04 11:58:0784export class SearchableContainer extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3785 /**
Tim van der Lippe18f04892020-03-17 11:39:4086 * @param {!TextUtils.ContentProvider.ContentProvider} resource
Blink Reformat4c46d092018-04-07 15:32:3787 * @param {string} highlighterType
88 * @param {boolean=} autoPrettyPrint
Blink Reformat4c46d092018-04-07 15:32:3789 */
90 constructor(resource, highlighterType, autoPrettyPrint) {
91 super(true);
Jack Franklin71519f82020-11-03 12:08:5992 this.registerRequiredCSS('source_frame/resourceSourceFrame.css', {enableLegacyPatching: true});
Tim van der Lippeb88663f2019-11-07 15:53:2193 const sourceFrame = new ResourceSourceFrame(resource, autoPrettyPrint);
Blink Reformat4c46d092018-04-07 15:32:3794 this._sourceFrame = sourceFrame;
95 sourceFrame.setHighlighterType(highlighterType);
Tim van der Lippe2543c5c2020-02-04 11:58:0796 const searchableView = new UI.SearchableView.SearchableView(sourceFrame);
Blink Reformat4c46d092018-04-07 15:32:3797 searchableView.element.classList.add('searchable-view');
98 searchableView.setPlaceholder(ls`Find`);
99 sourceFrame.show(searchableView.element);
100 sourceFrame.setSearchableView(searchableView);
101 searchableView.show(this.contentElement);
102
Tim van der Lippe2543c5c2020-02-04 11:58:07103 const toolbar = new UI.Toolbar.Toolbar('toolbar', this.contentElement);
Simon Zünd308c74f2020-01-16 06:53:37104 sourceFrame.toolbarItems().then(items => {
105 items.map(item => toolbar.appendToolbarItem(item));
106 });
Blink Reformat4c46d092018-04-07 15:32:37107 }
108
109 /**
110 * @param {number} lineNumber
111 * @param {number=} columnNumber
112 */
113 async revealPosition(lineNumber, columnNumber) {
114 this._sourceFrame.revealPosition(lineNumber, columnNumber, true);
115 }
Tim van der Lippeb88663f2019-11-07 15:53:21116}