File: capture_mode_behavior.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (749 lines) | stat: -rw-r--r-- 26,808 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/capture_mode/capture_mode_behavior.h"

#include <memory>
#include <utility>
#include <vector>

#include "ash/capture_mode/base_capture_mode_session.h"
#include "ash/capture_mode/capture_mode_camera_controller.h"
#include "ash/capture_mode/capture_mode_constants.h"
#include "ash/capture_mode/capture_mode_controller.h"
#include "ash/capture_mode/capture_mode_metrics.h"
#include "ash/capture_mode/capture_mode_types.h"
#include "ash/capture_mode/capture_mode_util.h"
#include "ash/capture_mode/game_capture_bar_view.h"
#include "ash/capture_mode/normal_capture_bar_view.h"
#include "ash/capture_mode/sunfish_capture_bar_view.h"
#include "ash/constants/ash_features.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/projector/projector_controller_impl.h"
#include "ash/public/cpp/capture_mode/capture_mode_api.h"
#include "ash/scanner/scanner_controller.h"
#include "ash/scanner/scanner_disclaimer.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/check.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "base/task/single_thread_task_runner.h"
#include "components/prefs/pref_service.h"
#include "ui/aura/window_observer.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/public/cpp/notification.h"

namespace ash {

namespace {

// Width of the full capture bar, which includes all the elements of the normal
// capture bar.
constexpr int kFullCaptureBarWidth = 376;

// Width of the game capture bar.
constexpr int kGameCaptureBarWidth = 250;

// Returns the current configs before been overwritten by the client-initiated
// capture mode session
CaptureModeSessionConfigs GetCaptureModeSessionConfigs() {
  CaptureModeController* controller = CaptureModeController::Get();
  CaptureModeSessionConfigs configs = CaptureModeSessionConfigs{
      controller->type(), controller->source(), controller->recording_type(),
      controller->audio_recording_mode(), controller->enable_demo_tools()};
  return configs;
}

void SetCaptureModeSessionConfigs(const CaptureModeSessionConfigs& configs) {
  CaptureModeController* controller = CaptureModeController::Get();
  controller->SetType(configs.type);
  controller->SetSource(configs.source);
  controller->SetRecordingType(configs.recording_type);
  controller->SetAudioRecordingMode(configs.audio_recording_mode);
  controller->EnableDemoTools(configs.demo_tools_enabled);
}

// -----------------------------------------------------------------------------
// DefaultBehavior:
// Implements the `CaptureModeBehavior` interface with behavior defined for the
// default capture mode.
class DefaultBehavior : public CaptureModeBehavior {
 public:
  DefaultBehavior()
      : CaptureModeBehavior(
            {CaptureModeType::kImage, CaptureModeSource::kRegion,
             RecordingType::kWebM, AudioRecordingMode::kOff,
             /*demo_tools_enabled=*/false},
            BehaviorType::kDefault) {}

  DefaultBehavior(const DefaultBehavior&) = delete;
  DefaultBehavior& operator=(const DefaultBehavior&) = delete;
  ~DefaultBehavior() override = default;

  // CaptureModeBehavior:
  void AttachToSession() override {
    // Do not override the session configs in `DefaultBehavior`, since the
    // source and type may have been set before the session was started and
    // initialized.
  }
  void DetachFromSession() override {
    if (auto* scanner_controller = Shell::Get()->scanner_controller()) {
      scanner_controller->OnSessionUIClosed();
    }
  }
  bool ShouldRegionOverlayBeAllowed() const override {
    // TODO(crbug.com/376103983): Verify `CaptureRegionOverlayController` works
    // correctly. It is always created in Sunfish session to paint the region
    // selection UI, but should only support text overlay if Scanner is enabled.
    return CanShowSunfishOrScannerUi();
  }
  bool CanPaintRegionOverlay() const override {
    auto* controller = CaptureModeController::Get();
    return controller->type() == CaptureModeType::kImage &&
           controller->source() == CaptureModeSource::kRegion;
  }
  bool ShouldShowGlowWhileProcessingCaptureType(
      PerformCaptureType capture_type) const override {
    return CanPaintRegionOverlay() && Shell::Get()->scanner_controller() &&
           capture_type == PerformCaptureType::kScanner;
  }
  bool ShouldEndSessionOnShowingSearchResults() const override { return true; }
  bool CanShowActionButtons() const override { return true; }
  void OnRegionSelectedOrAdjustedWhenActionContainerShowing() override {
    CHECK(ShouldShowDefaultActionButtonsInActionContainer());
    auto* capture_mode_controller = CaptureModeController::Get();
    if (features::IsCaptureModeOnDeviceOcrEnabled()) {
      // Perform text detection to determine whether the copy text and smart
      // actions buttons should be shown.
      capture_mode_controller->PerformCapture(
          PerformCaptureType::kTextDetection);
    } else {
      // Show the smart actions button regardless of whether there is text
      // in the selected area or not.
      BaseCaptureModeSession* session =
          capture_mode_controller->capture_mode_session();
      CHECK(session);
      session->AddSmartActionsButton();
    }
  }
};

// -----------------------------------------------------------------------------
// ProjectorBehavior:
// Implements the `CaptureModeBehavior` interface with behavior defined for the
// projector-initiated capture mode.
class ProjectorBehavior : public CaptureModeBehavior {
 public:
  ProjectorBehavior()
      : CaptureModeBehavior(
            {CaptureModeType::kVideo, CaptureModeSource::kFullscreen,
             RecordingType::kWebM, AudioRecordingMode::kMicrophone,
             /*demo_tools_enabled=*/true},
            BehaviorType::kProjector) {}

  ProjectorBehavior(const ProjectorBehavior&) = delete;
  ProjectorBehavior& operator=(const ProjectorBehavior&) = delete;
  ~ProjectorBehavior() override = default;

  bool ShouldImageCaptureTypeBeAllowed() const override { return false; }
  bool ShouldSaveToSettingsBeIncluded() const override { return false; }
  bool ShouldGifBeSupported() const override { return false; }
  bool ShouldShowPreviewNotification() const override { return false; }
  bool SupportsAudioRecordingMode(AudioRecordingMode mode) const override {
    switch (mode) {
      case AudioRecordingMode::kOff:
      case AudioRecordingMode::kSystem:
        // Projector does not support turning off audio recording nor recording
        // the system audio separately without the microphone.
        return false;
      case AudioRecordingMode::kMicrophone:
      case AudioRecordingMode::kSystemAndMicrophone:
        return true;
    }
  }
  bool ShouldCreateAnnotationsOverlayController() const override {
    return true;
  }
  bool ShouldShowUserNudge() const override { return false; }
  bool ShouldAutoSelectFirstCamera() const override { return true; }
  bool RequiresCaptureFolderCreation() const override { return true; }
  void CreateCaptureFolder(OnCaptureFolderCreatedCallback callback) override {
    ProjectorControllerImpl::Get()->CreateScreencastContainerFolder(
        base::BindOnce(&ProjectorBehavior::OnScreencastContainerFolderCreated,
                       weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
  }
  std::vector<RecordingType> GetSupportedRecordingTypes() const override {
    return std::vector<RecordingType>{RecordingType::kWebM};
  }
  const char* GetClientMetricComponent() const override { return "Projector."; }

 protected:
  int GetCaptureBarWidth() const override {
    return kFullCaptureBarWidth - capture_mode::kButtonSize.width() -
           capture_mode::kSpaceBetweenCaptureModeTypeButtons;
  }

 private:
  // Called when the Projector controller creates the DriveFS folder that will
  // host the video file along with the associated metadata file created by the
  // Projector session.
  void OnScreencastContainerFolderCreated(
      OnCaptureFolderCreatedCallback callback,
      const base::FilePath& capture_file_full_path) {
    base::FilePath path;
    // An empty path is sent to indicate an error.
    if (!capture_file_full_path.empty()) {
      path = capture_file_full_path.AddExtension("webm");
    }
    std::move(callback).Run(path);
  }

  base::WeakPtrFactory<ProjectorBehavior> weak_ptr_factory_{this};
};

// -----------------------------------------------------------------------------
// GameDashboardBehavior:
// Implements the `CaptureModeBehavior` interface with behaviors defined by the
// game dashboard-initiated capture mode.
class GameDashboardBehavior : public CaptureModeBehavior,
                              public aura::WindowObserver {
 public:
  GameDashboardBehavior()
      : CaptureModeBehavior(
            {CaptureModeType::kVideo, CaptureModeSource::kWindow,
             RecordingType::kWebM, AudioRecordingMode::kSystemAndMicrophone,
             /*demo_tools_enabled=*/false},
            BehaviorType::kGameDashboard) {}

  GameDashboardBehavior(const GameDashboardBehavior&) = delete;
  GameDashboardBehavior operator=(const GameDashboardBehavior&) = delete;
  ~GameDashboardBehavior() override = default;

  // CaptureModeBehavior:
  void AttachToSession() override {
    CaptureModeBehavior::AttachToSession();

    CaptureModeController* controller = CaptureModeController::Get();
    BaseCaptureModeSession* session = controller->capture_mode_session();
    CHECK(session);
    if (!pre_selected_window_) {
      base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
          FROM_HERE,
          base::BindOnce(
              [](base::WeakPtr<GameDashboardBehavior> game_dashboard_behavior,
                 CaptureModeController* controller) {
                if (controller->IsActive()) {
                  controller->Stop();
                }
              },
              weak_ptr_factory_.GetWeakPtr(), controller));
    } else {
      session->SetPreSelectedWindow(pre_selected_window_);
    }
  }

  void DetachFromSession() override {
    CaptureModeBehavior::DetachFromSession();

    if (pre_selected_window_) {
      pre_selected_window_->RemoveObserver(this);
      pre_selected_window_ = nullptr;
    }
  }

  bool ShouldImageCaptureTypeBeAllowed() const override { return false; }
  bool ShouldFulscreenCaptureSourceBeAllowed() const override { return false; }
  bool ShouldRegionCaptureSourceBeAllowed() const override { return false; }
  bool ShouldDemoToolsSettingsBeIncluded() const override { return false; }
  bool ShouldGifBeSupported() const override { return false; }
  bool ShouldShowUserNudge() const override { return false; }
  bool ShouldAutoSelectFirstCamera() const override {
    return !CaptureModeController::Get()
                ->camera_controller()
                ->did_user_ever_change_camera();
  }

  std::unique_ptr<CaptureModeBarView> CreateCaptureModeBarView() override {
    return std::make_unique<GameCaptureBarView>();
  }

  void SetPreSelectedWindow(aura::Window* pre_selected_window) override {
    CHECK(!pre_selected_window_);
    pre_selected_window_ = pre_selected_window;
    pre_selected_window_->AddObserver(this);
  }

  const char* GetClientMetricComponent() const override {
    return "GameDashboard.";
  }

  std::vector<message_center::ButtonInfo> GetNotificationButtonsInfo(
      bool for_video) const override {
    return {message_center::ButtonInfo{l10n_util::GetStringUTF16(
                for_video ? IDS_ASH_SCREEN_CAPTURE_SHARE_TO_YOUTUBE
                          : IDS_ASH_SCREEN_CAPTURE_BUTTON_EDIT)},
            message_center::ButtonInfo{l10n_util::GetStringUTF16(
                IDS_ASH_SCREEN_CAPTURE_BUTTON_DELETE)}};
  }

  void OnAudioRecordingModeChanged() override {
    capture_mode_configs_.audio_recording_mode =
        CaptureModeController::Get()->audio_recording_mode();
  }

  void OnDemoToolsSettingsChanged() override {
    capture_mode_configs_.demo_tools_enabled =
        CaptureModeController::Get()->enable_demo_tools();
  }

  // aura::WindowObserver:
  void OnWindowDestroying(aura::Window* window) override {
    CHECK_EQ(window, pre_selected_window_);
    pre_selected_window_->RemoveObserver(this);
    pre_selected_window_ = nullptr;
  }

 protected:
  // CaptureModeBehavior:
  gfx::Rect GetBarAnchorBoundsInScreen(aura::Window* root) const override {
    CHECK(pre_selected_window_);
    return pre_selected_window_->GetBoundsInScreen();
  }

  int GetCaptureBarBottomPadding() const override {
    return capture_mode::kGameCaptureBarBottomPadding;
  }

  int GetCaptureBarWidth() const override { return kGameCaptureBarWidth; }

 private:
  raw_ptr<aura::Window> pre_selected_window_ = nullptr;
  base::WeakPtrFactory<GameDashboardBehavior> weak_ptr_factory_{this};
};

// -----------------------------------------------------------------------------
// SunfishBehavior:
// Implements the `CaptureModeBehavior` interface with behavior defined for the
// sunfish capture mode.
class SunfishBehavior : public CaptureModeBehavior {
 public:
  SunfishBehavior()
      : CaptureModeBehavior(
            {CaptureModeType::kImage, CaptureModeSource::kRegion,
             RecordingType::kWebM, AudioRecordingMode::kOff,
             /*demo_tools_enabled=*/false},
            BehaviorType::kSunfish) {}

  SunfishBehavior(const SunfishBehavior&) = delete;
  SunfishBehavior& operator=(const SunfishBehavior&) = delete;
  ~SunfishBehavior() override = default;

  // CaptureModeBehavior:
  // The Scanner session is started from
  // `CaptureModeController::MaybeShowScannerDisclaimerOnSunfishStartup`.
  void DetachFromSession() override {
    CaptureModeBehavior::DetachFromSession();
    if (auto* scanner_controller = Shell::Get()->scanner_controller()) {
      scanner_controller->OnSessionUIClosed();
    }
  }
  bool ShouldRegionOverlayBeAllowed() const override {
    return CanShowSunfishOrScannerUi();
  }
  bool CanPaintRegionOverlay() const override { return true; }
  bool ShouldShowGlowWhileProcessingCaptureType(
      PerformCaptureType capture_type) const override {
    return CanPaintRegionOverlay();
  }
  bool ShouldShowUserNudge() const override { return false; }
  bool ShouldReShowUisAtPerformingCapture(
      PerformCaptureType capture_type) const override {
    return true;
  }
  bool ShouldShowDefaultActionButtonsInActionContainer() const override {
    // We show action buttons in Sunfish mode for individual Scanner actions,
    // which is a different set of buttons to the default action buttons shown
    // in normal capture mode (search, copy text, smart actions button).
    return false;
  }
  bool ShouldShowCaptureButtonAfterRegionSelected() const override {
    return false;
  }
  bool ShouldPaintSunfishCaptureRegion() const override { return true; }
  bool CanShowActionButtons() const override { return true; }
  bool ShouldEndSessionOnSearchResultClicked() const override { return true; }
  bool NeedsDisclaimerOnInit() const override {
    // Return true if Scanner is enabled and any type of disclaimer should be
    // shown at the start of a Sunfish-session.
    return ScannerController::CanShowUiForShell() &&
           GetScannerDisclaimerType(
               *capture_mode_util::GetActiveUserPrefService(),
               ScannerEntryPoint::kSunfishSession) !=
               ScannerDisclaimerType::kNone;
  }
  bool ShouldAnnounceCaptureModeUIOnDisclaimerDismissed() const override {
    return true;
  }
  const std::u16string GetCaptureLabelRegionText() const override {
    return l10n_util::GetStringUTF16(
        IDS_ASH_SUNFISH_CAPTURE_LABEL_KEYBOARD_NAVIGATION);
  }
  const std::u16string GetActionButtonContainerTitle() const override {
    return l10n_util::GetStringUTF16(
        IDS_ASH_SCREEN_CAPTURE_SUNFISH_ACTION_BUTTON_WINDOW_TITLE);
  }
  const std::u16string GetCaptureModeBarTitle() const override {
    // The capture mode bar window does not need a title for Sunfish behavior
    // since it only contains a close button.
    return u"";
  }
  const std::string GetCaptureModeOpenAnnouncement() const override {
    return l10n_util::GetStringUTF8(IDS_ASH_SUNFISH_MODE_ALERT_OPEN);
  }
  int GetCaptureBarWidth() const override {
    // Return the height so the button is circular.
    return capture_mode::kCaptureBarHeight;
  }
  std::unique_ptr<CaptureModeBarView> CreateCaptureModeBarView() override {
    return std::make_unique<SunfishCaptureBarView>();
  }
  void OnRegionSelectedOrAdjustedWhenActionContainerShowing() override {
    auto* controller = CaptureModeController::Get();
    controller->MaybeUpdateSearchResultsPanelBounds();

    // `CaptureModeController` will perform DLP restriction checks and determine
    // whether the image can be sent for search.
    controller->PerformCapture(PerformCaptureType::kSunfish);
  }
  void OnEnterKeyPressed() override {}
};

}  // namespace

// -----------------------------------------------------------------------------
// CaptureModeBehavior:

CaptureModeBehavior::CaptureModeBehavior(
    const CaptureModeSessionConfigs& configs,
    const BehaviorType behavior_type)
    : capture_mode_configs_(configs), behavior_type_(behavior_type) {}

CaptureModeBehavior::~CaptureModeBehavior() = default;

// static
std::unique_ptr<CaptureModeBehavior> CaptureModeBehavior::Create(
    BehaviorType behavior_type) {
  switch (behavior_type) {
    case BehaviorType::kProjector:
      return std::make_unique<ProjectorBehavior>();
    case BehaviorType::kGameDashboard:
      return std::make_unique<GameDashboardBehavior>();
    case BehaviorType::kDefault:
      return std::make_unique<DefaultBehavior>();
    case BehaviorType::kSunfish:
      return std::make_unique<SunfishBehavior>();
  }
}

void CaptureModeBehavior::AttachToSession() {
  cached_configs_ = GetCaptureModeSessionConfigs();

  // Overwrite the current capture mode session with the behavior
  // configurations.
  SetCaptureModeSessionConfigs(capture_mode_configs_);
}

void CaptureModeBehavior::DetachFromSession() {
  CHECK(cached_configs_);

  // Restore the capture mode configurations after being overwritten with the
  // behavior-specific configurations.
  SetCaptureModeSessionConfigs(cached_configs_.value());
  cached_configs_.reset();
}

bool CaptureModeBehavior::ShouldRegionOverlayBeAllowed() const {
  return false;
}

bool CaptureModeBehavior::CanPaintRegionOverlay() const {
  return false;
}

bool CaptureModeBehavior::ShouldShowGlowWhileProcessingCaptureType(
    PerformCaptureType capture_type) const {
  return false;
}

bool CaptureModeBehavior::ShouldImageCaptureTypeBeAllowed() const {
  return true;
}

bool CaptureModeBehavior::ShouldVideoCaptureTypeBeAllowed() const {
  return true;
}

bool CaptureModeBehavior::ShouldFulscreenCaptureSourceBeAllowed() const {
  return true;
}

bool CaptureModeBehavior::ShouldRegionCaptureSourceBeAllowed() const {
  return true;
}

bool CaptureModeBehavior::ShouldWindowCaptureSourceBeAllowed() const {
  return true;
}

bool CaptureModeBehavior::SupportsAudioRecordingMode(
    AudioRecordingMode mode) const {
  switch (mode) {
    case AudioRecordingMode::kOff:
    case AudioRecordingMode::kMicrophone:
    case AudioRecordingMode::kSystem:
    case AudioRecordingMode::kSystemAndMicrophone:
      return true;
  }
}

bool CaptureModeBehavior::ShouldCameraSelectionSettingsBeIncluded() const {
  return true;
}

bool CaptureModeBehavior::ShouldDemoToolsSettingsBeIncluded() const {
  return true;
}

bool CaptureModeBehavior::ShouldSaveToSettingsBeIncluded() const {
  return true;
}

bool CaptureModeBehavior::ShouldGifBeSupported() const {
  return true;
}

bool CaptureModeBehavior::ShouldShowPreviewNotification() const {
  return true;
}

bool CaptureModeBehavior::ShouldSkipVideoRecordingCountDown() const {
  return false;
}

bool CaptureModeBehavior::ShouldCreateAnnotationsOverlayController() const {
  if (base::FeatureList::IsEnabled(ash::features::kAnnotatorMode)) {
    return true;
  }
  return false;
}

bool CaptureModeBehavior::ShouldShowUserNudge() const {
  return true;
}

bool CaptureModeBehavior::ShouldAutoSelectFirstCamera() const {
  return false;
}

bool CaptureModeBehavior::RequiresCaptureFolderCreation() const {
  return false;
}

bool CaptureModeBehavior::ShouldReShowUisAtPerformingCapture(
    PerformCaptureType capture_type) const {
  switch (capture_type) {
    case PerformCaptureType::kCapture:
      // The session shuts down after image capture so there is no need to
      // reshow the UIs. For video recording, we need to reshow the UIs so that
      // we can start the 3-second count down animation.
      return CaptureModeController::Get()->type() != CaptureModeType::kImage;
    case PerformCaptureType::kSearch:
      // The session shuts down after capture for `PerformCaptureType::kSearch`
      // so there is no need to reshow the UIs.
      return false;
    case PerformCaptureType::kScanner:
    case PerformCaptureType::kTextDetection:
    case PerformCaptureType::kSunfish:
      return true;
  }
}

bool CaptureModeBehavior::ShouldShowDefaultActionButtonsInActionContainer()
    const {
  return true;
}

bool CaptureModeBehavior::CanShowActionButtons() const {
  return false;
}

bool CaptureModeBehavior::ShouldPaintSunfishCaptureRegion() const {
  return false;
}

bool CaptureModeBehavior::ShouldShowCaptureButtonAfterRegionSelected() const {
  return true;
}

bool CaptureModeBehavior::ShouldEndSessionOnShowingSearchResults() const {
  return false;
}

bool CaptureModeBehavior::ShouldEndSessionOnSearchResultClicked() const {
  return false;
}

bool CaptureModeBehavior::NeedsDisclaimerOnInit() const {
  return false;
}

bool CaptureModeBehavior::ShouldAnnounceCaptureModeUIOnDisclaimerDismissed()
    const {
  return false;
}

void CaptureModeBehavior::CreateCaptureFolder(
    OnCaptureFolderCreatedCallback callback) {
  NOTREACHED();
}

std::vector<RecordingType> CaptureModeBehavior::GetSupportedRecordingTypes()
    const {
  return {RecordingType::kWebM, RecordingType::kGif};
}

void CaptureModeBehavior::SetPreSelectedWindow(
    aura::Window* pre_selected_window) {
  NOTREACHED();
}

const char* CaptureModeBehavior::GetClientMetricComponent() const {
  return "";
}

std::vector<message_center::ButtonInfo>
CaptureModeBehavior::GetNotificationButtonsInfo(bool for_video) const {
  std::vector<message_center::ButtonInfo> buttons_info;

  if (!for_video &&
      !Shell::Get()->session_controller()->IsUserSessionBlocked()) {
    buttons_info.emplace_back(
        l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_EDIT));
  }

  buttons_info.emplace_back(
      l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_BUTTON_DELETE));

  return buttons_info;
}

const std::u16string CaptureModeBehavior::GetCaptureLabelRegionText() const {
  CaptureModeController* controller = CaptureModeController::Get();
  DCHECK(controller->user_capture_region().IsEmpty());
  return l10n_util::GetStringUTF16(
      controller->type() == CaptureModeType::kImage
          ? IDS_ASH_SCREEN_CAPTURE_LABEL_REGION_IMAGE_CAPTURE_KEYBOARD_NAVIGATION
          : IDS_ASH_SCREEN_CAPTURE_LABEL_REGION_VIDEO_RECORD_KEYBOARD_NAVIGATION);
}

const std::u16string CaptureModeBehavior::GetActionButtonContainerTitle()
    const {
  return l10n_util::GetStringUTF16(
      IDS_ASH_SCREEN_CAPTURE_DEFAULT_ACTION_BUTTON_WINDOW_TITLE);
}

const std::u16string CaptureModeBehavior::GetCaptureModeBarTitle() const {
  return l10n_util::GetStringUTF16(IDS_ASH_SCREEN_CAPTURE_A11Y_TITLE);
}

const std::string CaptureModeBehavior::GetCaptureModeOpenAnnouncement() const {
  CaptureModeController* controller = CaptureModeController::Get();
  int capture_source_id;
  switch (controller->source()) {
    case CaptureModeSource::kFullscreen:
      capture_source_id = IDS_ASH_SCREEN_CAPTURE_SOURCE_FULLSCREEN;
      break;
    case CaptureModeSource::kRegion:
      capture_source_id = IDS_ASH_SCREEN_CAPTURE_SOURCE_PARTIAL;
      break;
    case CaptureModeSource::kWindow:
      capture_source_id = IDS_ASH_SCREEN_CAPTURE_SOURCE_WINDOW;
      break;
  }

  return l10n_util::GetStringFUTF8(
      IDS_ASH_SCREEN_CAPTURE_KEYBOARD_NAVIGATION_ALERT_OPEN_REVISED,
      l10n_util::GetStringUTF16(capture_source_id),
      l10n_util::GetStringUTF16(
          controller->type() == CaptureModeType::kImage
              ? IDS_ASH_SCREEN_CAPTURE_TYPE_SCREENSHOT
              : IDS_ASH_SCREEN_CAPTURE_TYPE_SCREEN_RECORDING));
}

std::unique_ptr<CaptureModeBarView>
CaptureModeBehavior::CreateCaptureModeBarView() {
  return std::make_unique<NormalCaptureBarView>(this);
}

gfx::Rect CaptureModeBehavior::GetCaptureBarBounds(aura::Window* root) const {
  auto bounds = GetBarAnchorBoundsInScreen(root);
  const int bar_y = bounds.bottom() - GetCaptureBarBottomPadding() -
                    capture_mode::kCaptureBarHeight;
  bounds.ClampToCenteredSize(
      gfx::Size(GetCaptureBarWidth(), capture_mode::kCaptureBarHeight));
  bounds.set_y(bar_y);
  return bounds;
}

gfx::Rect CaptureModeBehavior::GetBarAnchorBoundsInScreen(
    aura::Window* root) const {
  CHECK(root);
  auto bounds = root->GetBoundsInScreen();
  int new_bottom = bounds.bottom();

  Shelf* shelf = Shelf::ForWindow(root);
  if (shelf->IsHorizontalAlignment()) {
    // Get the widget which has the shelf icons. This is the hotseat widget if
    // the hotseat is extended, shelf widget otherwise.
    const bool hotseat_extended =
        shelf->shelf_layout_manager()->hotseat_state() ==
        HotseatState::kExtended;
    views::Widget* shelf_widget =
        hotseat_extended ? static_cast<views::Widget*>(shelf->hotseat_widget())
                         : static_cast<views::Widget*>(shelf->shelf_widget());
    new_bottom = shelf_widget->GetWindowBoundsInScreen().y();
  }
  bounds.set_height(new_bottom - bounds.y());
  return bounds;
}

int CaptureModeBehavior::GetCaptureBarBottomPadding() const {
  return capture_mode::kCaptureBarBottomPadding;
}

int CaptureModeBehavior::GetCaptureBarWidth() const {
  return kFullCaptureBarWidth;
}

void CaptureModeBehavior::OnAudioRecordingModeChanged() {}

void CaptureModeBehavior::OnDemoToolsSettingsChanged() {}

void CaptureModeBehavior::
    OnRegionSelectedOrAdjustedWhenActionContainerShowing() {}

void CaptureModeBehavior::OnEnterKeyPressed() {
  CaptureModeController::Get()->PerformCapture();
}

}  // namespace ash