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

Unified Diff: sky/sdk/lib/framework/components2/popup_menu.dart

Issue 1177243002: Refactor fn2.dart, since it breached our 1000-line threshold. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: sky/sdk/lib/framework/components2/popup_menu.dart
diff --git a/sky/sdk/lib/framework/components2/popup_menu.dart b/sky/sdk/lib/framework/components2/popup_menu.dart
deleted file mode 100644
index 62e93f8d4901d000fe146dc19fa4b096d6451895..0000000000000000000000000000000000000000
--- a/sky/sdk/lib/framework/components2/popup_menu.dart
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-import 'dart:async';
-import 'dart:math' as math;
-import 'dart:sky' as sky;
-
-import '../animation/animated_value.dart';
-import '../fn2.dart';
-import '../painting/box_painter.dart';
-import '../theme2/colors.dart';
-import '../theme2/shadows.dart';
-import 'animated_component.dart';
-import 'material.dart';
-import 'popup_menu_item.dart';
-
-const double _kMenuOpenDuration = 300.0;
-const double _kMenuCloseDuration = 200.0;
-const double _kMenuCloseDelay = 100.0;
-
-enum MenuState { hidden, opening, open, closing }
-
-class PopupMenuController {
- AnimatedValue position = new AnimatedValue(0.0);
- MenuState _state = MenuState.hidden;
- MenuState get state => _state;
-
- bool get canReact => (_state == MenuState.opening) || (_state == MenuState.open);
-
- open() async {
- if (_state != MenuState.hidden)
- return;
- _state = MenuState.opening;
- if (await position.animateTo(1.0, _kMenuOpenDuration) == 1.0)
- _state = MenuState.open;
- }
-
- Future _closeState;
- close() async {
- var result = new Completer();
- _closeState = result.future;
- if ((_state == MenuState.opening) || (_state == MenuState.open)) {
- _state = MenuState.closing;
- await position.animateTo(0.0, _kMenuCloseDuration, initialDelay: _kMenuCloseDelay);
- _state = MenuState.hidden;
- _closeState = null;
- result.complete();
- return result.future;
- }
- assert(_closeState != null);
- return _closeState;
- }
-}
-
-class PopupMenu extends AnimatedComponent {
-
- PopupMenu({ Object key, this.controller, this.items, this.level })
- : super(key: key) {
- _painter = new BoxPainter(new BoxDecoration(
- backgroundColor: Grey[50],
- borderRadius: 2.0,
- boxShadow: Shadow[level]));
-
- animate(controller.position, (double value) {
- _position = value;
- });
- }
-
- PopupMenuController controller;
- List<List<UINode>> items;
- int level;
-
- void syncFields(PopupMenu source) {
- controller = source.controller;
- items = source.items;
- level = source.level;
- _painter = source._painter;
- super.syncFields(source);
- }
-
- double _position;
- BoxPainter _painter;
-
- double _opacityFor(int i) {
- if (_position == null || _position == 1.0)
- return 1.0;
- double unit = 1.0 / items.length;
- double duration = 1.5 * unit;
- double start = i * unit;
- return math.max(0.0, math.min(1.0, (_position - start) / duration));
- }
-
- UINode build() {
- int i = 0;
- List<UINode> children = new List.from(items.map((List<UINode> item) {
- double opacity = _opacityFor(i);
- return new PopupMenuItem(key: i++, children: item, opacity: opacity);
- }));
-
- return new Opacity(
- opacity: math.min(1.0, _position * 3.0),
- child: new ShrinkWrapWidth(
- child: new CustomPaint(
- callback: (sky.Canvas canvas, Size size) {
- double width = math.min(size.width, size.width * (0.5 + _position * 2.0));
- double height = math.min(size.height, size.height * _position * 1.5);
- _painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, width, height));
- },
- child: new Container(
- padding: const EdgeDims.all(8.0),
- child: new Block(children)
- )
- )
- )
- );
- }
-
-}
« no previous file with comments | « sky/sdk/lib/framework/components2/modal_overlay.dart ('k') | sky/sdk/lib/framework/components2/popup_menu_item.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698