| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library debugger_page_element; | 5 library debugger_page_element; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'observatory_element.dart'; | 9 import 'observatory_element.dart'; |
| 10 import 'package:observatory/cli.dart'; | 10 import 'package:observatory/cli.dart'; |
| (...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 }); | 1846 }); |
| 1847 } | 1847 } |
| 1848 } | 1848 } |
| 1849 | 1849 |
| 1850 @CustomTag('debugger-console') | 1850 @CustomTag('debugger-console') |
| 1851 class DebuggerConsoleElement extends ObservatoryElement { | 1851 class DebuggerConsoleElement extends ObservatoryElement { |
| 1852 @published Isolate isolate; | 1852 @published Isolate isolate; |
| 1853 | 1853 |
| 1854 DebuggerConsoleElement.created() : super.created(); | 1854 DebuggerConsoleElement.created() : super.created(); |
| 1855 | 1855 |
| 1856 /// Is [container] scrolled to the within [threshold] pixels of the bottom? |
| 1857 static bool _isScrolledToBottom(DivElement container, [int threshold = 2]) { |
| 1858 if (container == null) { |
| 1859 return false; |
| 1860 } |
| 1861 // scrollHeight -> complete height of element including scrollable area. |
| 1862 // clientHeight -> height of element on page. |
| 1863 // scrollTop -> how far is an element scrolled (from 0 to scrollHeight). |
| 1864 final distanceFromBottom = |
| 1865 container.scrollHeight - container.clientHeight - container.scrollTop; |
| 1866 const threshold = 2; // 2 pixel slop. |
| 1867 return distanceFromBottom <= threshold; |
| 1868 } |
| 1869 |
| 1870 /// Scroll [container] so the bottom content is visible. |
| 1871 static _scrollToBottom(DivElement container) { |
| 1872 if (container == null) { |
| 1873 return; |
| 1874 } |
| 1875 // Adjust scroll so that the bottom of the content is visible. |
| 1876 container.scrollTop = container.scrollHeight - container.clientHeight; |
| 1877 } |
| 1878 |
| 1879 void _append(HtmlElement span) { |
| 1880 var consoleTextElement = $['consoleText']; |
| 1881 bool autoScroll = _isScrolledToBottom(parent); |
| 1882 consoleTextElement.children.add(span); |
| 1883 if (autoScroll) { |
| 1884 _scrollToBottom(parent); |
| 1885 } |
| 1886 } |
| 1887 |
| 1856 void print(String line, { bool newline:true }) { | 1888 void print(String line, { bool newline:true }) { |
| 1857 var span = new SpanElement(); | 1889 var span = new SpanElement(); |
| 1858 span.classes.add('normal'); | 1890 span.classes.add('normal'); |
| 1859 span.appendText(line); | 1891 span.appendText(line); |
| 1860 if (newline) { | 1892 if (newline) { |
| 1861 span.appendText('\n'); | 1893 span.appendText('\n'); |
| 1862 } | 1894 } |
| 1863 $['consoleText'].children.add(span); | 1895 _append(span); |
| 1864 span.scrollIntoView(); | |
| 1865 } | 1896 } |
| 1866 | 1897 |
| 1867 void printBold(String line, { bool newline:true }) { | 1898 void printBold(String line, { bool newline:true }) { |
| 1868 var span = new SpanElement(); | 1899 var span = new SpanElement(); |
| 1869 span.classes.add('bold'); | 1900 span.classes.add('bold'); |
| 1870 span.appendText(line); | 1901 span.appendText(line); |
| 1871 if (newline) { | 1902 if (newline) { |
| 1872 span.appendText('\n'); | 1903 span.appendText('\n'); |
| 1873 } | 1904 } |
| 1874 $['consoleText'].children.add(span); | 1905 _append(span); |
| 1875 span.scrollIntoView(); | |
| 1876 } | 1906 } |
| 1877 | 1907 |
| 1878 void printRed(String line, { bool newline:true }) { | 1908 void printRed(String line, { bool newline:true }) { |
| 1879 var span = new SpanElement(); | 1909 var span = new SpanElement(); |
| 1880 span.classes.add('red'); | 1910 span.classes.add('red'); |
| 1881 span.appendText(line); | 1911 span.appendText(line); |
| 1882 if (newline) { | 1912 if (newline) { |
| 1883 span.appendText('\n'); | 1913 span.appendText('\n'); |
| 1884 } | 1914 } |
| 1885 $['consoleText'].children.add(span); | 1915 _append(span); |
| 1886 span.scrollIntoView(); | |
| 1887 } | 1916 } |
| 1888 | 1917 |
| 1889 void printStdio(List<String> lines) { | 1918 void printStdio(List<String> lines) { |
| 1890 var lastSpan; | 1919 var consoleTextElement = $['consoleText']; |
| 1920 bool autoScroll = _isScrolledToBottom(parent); |
| 1891 for (var line in lines) { | 1921 for (var line in lines) { |
| 1892 var span = new SpanElement(); | 1922 var span = new SpanElement(); |
| 1893 span.classes.add('green'); | 1923 span.classes.add('green'); |
| 1894 span.appendText(line); | 1924 span.appendText(line); |
| 1895 span.appendText('\n'); | 1925 span.appendText('\n'); |
| 1896 $['consoleText'].children.add(span); | 1926 consoleTextElement.children.add(span); |
| 1897 lastSpan = span; | |
| 1898 } | 1927 } |
| 1899 if (lastSpan != null) { | 1928 if (autoScroll) { |
| 1900 lastSpan.scrollIntoView(); | 1929 _scrollToBottom(parent); |
| 1901 } | 1930 } |
| 1902 } | 1931 } |
| 1903 | 1932 |
| 1904 void printRef(Instance ref, { bool newline:true }) { | 1933 void printRef(Instance ref, { bool newline:true }) { |
| 1905 var refElement = new Element.tag('instance-ref'); | 1934 var refElement = new Element.tag('instance-ref'); |
| 1906 refElement.ref = ref; | 1935 refElement.ref = ref; |
| 1907 $['consoleText'].children.add(refElement); | 1936 _append(refElement); |
| 1908 if (newline) { | 1937 if (newline) { |
| 1909 this.newline(); | 1938 this.newline(); |
| 1910 } | 1939 } |
| 1911 refElement.scrollIntoView(); | |
| 1912 } | 1940 } |
| 1913 | 1941 |
| 1914 void newline() { | 1942 void newline() { |
| 1915 var br = new BRElement(); | 1943 _append(new BRElement()); |
| 1916 $['consoleText'].children.add(br); | |
| 1917 br.scrollIntoView(); | |
| 1918 } | 1944 } |
| 1919 } | 1945 } |
| 1920 | 1946 |
| 1921 @CustomTag('debugger-input') | 1947 @CustomTag('debugger-input') |
| 1922 class DebuggerInputElement extends ObservatoryElement { | 1948 class DebuggerInputElement extends ObservatoryElement { |
| 1923 @published Isolate isolate; | 1949 @published Isolate isolate; |
| 1924 @published String text = ''; | 1950 @published String text = ''; |
| 1925 @observable ObservatoryDebugger debugger; | 1951 @observable ObservatoryDebugger debugger; |
| 1926 @observable bool busy = false; | 1952 @observable bool busy = false; |
| 1927 | 1953 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 } | 2001 } |
| 1976 }); | 2002 }); |
| 1977 } | 2003 } |
| 1978 | 2004 |
| 1979 void focus() { | 2005 void focus() { |
| 1980 $['textBox'].focus(); | 2006 $['textBox'].focus(); |
| 1981 } | 2007 } |
| 1982 | 2008 |
| 1983 DebuggerInputElement.created() : super.created(); | 2009 DebuggerInputElement.created() : super.created(); |
| 1984 } | 2010 } |
| OLD | NEW |