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

Side by Side Diff: ui/views/controls/non_md_slider.cc

Issue 2692043009: Remove last MD reference from TrayPopupUtils. (Closed)
Patch Set: rebase Created 3 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
« no previous file with comments | « ui/views/controls/non_md_slider.h ('k') | ui/views/controls/slider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/controls/non_md_slider.h"
6
7 #include "ui/base/resource/resource_bundle.h"
8 #include "ui/gfx/canvas.h"
9 #include "ui/gfx/geometry/point.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/resources/grit/ui_resources.h"
12 #include "ui/views/controls/slider.h"
13 #include "ui/views/resources/grit/views_resources.h"
14
15 namespace {
16 const int kBarImagesActive[] = {
17 IDR_SLIDER_ACTIVE_LEFT, IDR_SLIDER_ACTIVE_CENTER, IDR_SLIDER_PRESSED_CENTER,
18 IDR_SLIDER_PRESSED_RIGHT,
19 };
20
21 const int kBarImagesDisabled[] = {
22 IDR_SLIDER_DISABLED_LEFT, IDR_SLIDER_DISABLED_CENTER,
23 IDR_SLIDER_DISABLED_CENTER, IDR_SLIDER_DISABLED_RIGHT,
24 };
25
26 // The image chunks.
27 enum BorderElements {
28 LEFT,
29 CENTER_LEFT,
30 CENTER_RIGHT,
31 RIGHT,
32 };
33 } // namespace
34
35 namespace views {
36
37 NonMdSlider::NonMdSlider(SliderListener* listener)
38 : Slider(listener),
39 bar_active_images_(kBarImagesActive),
40 bar_disabled_images_(kBarImagesDisabled) {
41 UpdateSliderAppearance(true);
42 }
43
44 NonMdSlider::~NonMdSlider() {}
45
46 void NonMdSlider::OnPaint(gfx::Canvas* canvas) {
47 Slider::OnPaint(canvas);
48 gfx::Rect content = GetContentsBounds();
49 float value = GetAnimatingValue();
50
51 // Inset the slider bar a little bit, so that the left or the right end of
52 // the slider bar will not be exposed under the thumb button when the thumb
53 // button slides to the left most or right most position.
54 const int kBarInsetX = 2;
55 int bar_width = content.width() - kBarInsetX * 2;
56 int bar_cy = content.height() / 2 - bar_height_ / 2;
57
58 int w = content.width() - thumb_->width();
59 int full = value * w;
60 int middle = std::max(full, images_[LEFT]->width());
61
62 canvas->Save();
63 canvas->Translate(gfx::Vector2d(kBarInsetX, bar_cy));
64 canvas->DrawImageInt(*images_[LEFT], 0, 0);
65 canvas->DrawImageInt(*images_[RIGHT], bar_width - images_[RIGHT]->width(), 0);
66 canvas->TileImageInt(*images_[CENTER_LEFT], images_[LEFT]->width(), 0,
67 middle - images_[LEFT]->width(), bar_height_);
68 canvas->TileImageInt(*images_[CENTER_RIGHT], middle, 0,
69 bar_width - middle - images_[RIGHT]->width(),
70 bar_height_);
71 canvas->Restore();
72
73 // Paint slider thumb.
74 int button_cx = content.x() + full;
75 int thumb_y = content.height() / 2 - thumb_->height() / 2;
76 canvas->DrawImageInt(*thumb_, button_cx, thumb_y);
77 }
78
79 const char* NonMdSlider::GetClassName() const {
80 return "NonMdSlider";
81 }
82
83 void NonMdSlider::UpdateState(bool control_on) {
84 UpdateSliderAppearance(control_on);
85 }
86
87 void NonMdSlider::UpdateSliderAppearance(bool control_on) {
88 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
89 if (control_on) {
90 thumb_ = rb.GetImageNamed(IDR_SLIDER_ACTIVE_THUMB).ToImageSkia();
91 for (int i = 0; i < 4; ++i)
92 images_[i] = rb.GetImageNamed(bar_active_images_[i]).ToImageSkia();
93 } else {
94 thumb_ = rb.GetImageNamed(IDR_SLIDER_DISABLED_THUMB).ToImageSkia();
95 for (int i = 0; i < 4; ++i)
96 images_[i] = rb.GetImageNamed(bar_disabled_images_[i]).ToImageSkia();
97 }
98 bar_height_ = images_[LEFT]->height();
99 SchedulePaint();
100 }
101
102 int NonMdSlider::GetThumbWidth() {
103 return thumb_->width();
104 }
105
106 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/non_md_slider.h ('k') | ui/views/controls/slider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698