| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/examples/vector_example.h" | 5 #include "ui/views/examples/vector_example.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // ButtonListener | 121 // ButtonListener |
| 122 void ButtonPressed(Button* sender, const ui::Event& event) override { | 122 void ButtonPressed(Button* sender, const ui::Event& event) override { |
| 123 DCHECK_EQ(file_go_button_, sender); | 123 DCHECK_EQ(file_go_button_, sender); |
| 124 std::string contents; | 124 std::string contents; |
| 125 #if defined(OS_POSIX) | 125 #if defined(OS_POSIX) |
| 126 base::FilePath path(base::UTF16ToUTF8(file_chooser_->text())); | 126 base::FilePath path(base::UTF16ToUTF8(file_chooser_->text())); |
| 127 #elif defined(OS_WIN) | 127 #elif defined(OS_WIN) |
| 128 base::FilePath path(file_chooser_->text()); | 128 base::FilePath path(file_chooser_->text()); |
| 129 #endif | 129 #endif |
| 130 base::ReadFileToString(path, &contents); | 130 base::ReadFileToString(path, &contents); |
| 131 // Skip over comments. |
| 132 for (size_t slashes = contents.find("//"); slashes != std::string::npos; |
| 133 slashes = contents.find("//")) { |
| 134 size_t eol = contents.find("\n", slashes); |
| 135 contents.erase(slashes, eol - slashes); |
| 136 } |
| 131 image_view_->SetImage( | 137 image_view_->SetImage( |
| 132 gfx::CreateVectorIconFromSource(contents, size_, color_)); | 138 gfx::CreateVectorIconFromSource(contents, size_, color_)); |
| 133 } | 139 } |
| 134 | 140 |
| 135 void UpdateImage() { | 141 void UpdateImage() { |
| 136 image_view_->SetImage(gfx::CreateVectorIcon( | 142 image_view_->SetImage(gfx::CreateVectorIcon( |
| 137 static_cast<gfx::VectorIconId>(vector_id_), size_, color_)); | 143 static_cast<gfx::VectorIconId>(vector_id_), size_, color_)); |
| 138 Layout(); | 144 Layout(); |
| 139 } | 145 } |
| 140 | 146 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 159 | 165 |
| 160 VectorExample::~VectorExample() {} | 166 VectorExample::~VectorExample() {} |
| 161 | 167 |
| 162 void VectorExample::CreateExampleView(View* container) { | 168 void VectorExample::CreateExampleView(View* container) { |
| 163 container->SetLayoutManager(new FillLayout()); | 169 container->SetLayoutManager(new FillLayout()); |
| 164 container->AddChildView(new VectorIconGallery()); | 170 container->AddChildView(new VectorIconGallery()); |
| 165 } | 171 } |
| 166 | 172 |
| 167 } // namespace examples | 173 } // namespace examples |
| 168 } // namespace views | 174 } // namespace views |
| OLD | NEW |